meta data for this page
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:bash [2022/11/30 10:04] – niziak | linux:bash [2026/05/05 12:13] (current) – niziak | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Bash ====== | ====== Bash ====== | ||
| - | ===== rerun as other user ===== | + | |
| + | ===== re-run | ||
| <code bash> | <code bash> | ||
| if [ $UID == 0 ]; then | if [ $UID == 0 ]; then | ||
| - | | + | |
| fi | fi | ||
| </ | </ | ||
| Line 15: | Line 16: | ||
| exit 1 | exit 1 | ||
| fi | fi | ||
| + | </ | ||
| + | |||
| + | and use it inside loop: | ||
| + | <code bash> | ||
| + | for tool in awk bc sed; do | ||
| + | .... | ||
| + | done | ||
| </ | </ | ||
| Line 97: | Line 105: | ||
| </ | </ | ||
| - | ===== include/ | ||
| - | Possible test scenario: | ||
| - | - call using from another directory full path / | ||
| - | - add / | ||
| - | - create symlink to script and call using symlink. Check for relative and absolute symlinks. | ||
| - | - it should work also if it is sourced " | ||
| - | |||
| - | The best is to create setup/ | ||
| - | |||
| - | Another solutions: | ||
| - | <code bash> | ||
| - | #!/bin/sh | ||
| - | MY_DIR=$(dirname $(readlink -f $0)) | ||
| - | $MY_DIR/ | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | DIR=$( cd "$( dirname " | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | # Works correctly if script is sourced from another one | ||
| - | DIR=" | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | cur_file=" | ||
| - | cur_dir=" | ||
| - | </ | ||
| - | |||
| - | '' | ||
| - | An array variable whose members are the source filenames where the | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | '' | ||