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/06/08 18:42] – niziak | linux:bash [2023/11/23 06:57] (current) – niziak | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Bash ====== | ====== Bash ====== | ||
| + | |||
| + | ===== re-run as other user ===== | ||
| + | |||
| + | <code bash> | ||
| + | if [ $UID == 0 ]; then | ||
| + |     exec su -c " | ||
| + | fi | ||
| + | </ | ||
| + | |||
| + | ===== Check if command is installed ===== | ||
| + | |||
| + | <code bash> | ||
| + | if ! command -v " | ||
| + | echo " Command ${TOOL} not found. Please install it" | ||
| + | exit 1 | ||
| + | fi | ||
| + | </ | ||
| + | |||
| + | and use it inside loop: | ||
| + | <code bash> | ||
| + | for tool in awk bc sed; do | ||
| + | .... | ||
| + | done | ||
| + | </ | ||
| ===== Output ===== | ===== Output ===== | ||
| Line 102: | Line 126: | ||
| <code bash> | <code bash> | ||
| - | DIR=" | + | # Works correctly if script is sourced from another one | 
| + | DIR=" | ||
| </ | </ | ||