meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:bash [2022/06/08 16:58] niziaklinux:bash [2023/11/23 05:57] (current) niziak
Line 1: Line 1:
 ====== Bash ====== ====== Bash ======
 +
 +===== re-run as other user =====
 +
 +<code bash>
 +if [ $UID == 0 ]; then
 +    exec su -c "$0" john
 +fi
 +</code>
 +
 +===== Check if command is installed =====
 +
 +<code bash>
 +if ! command -v "${TOOL}" &>/dev/null; then
 +    echo " Command ${TOOL} not found. Please install it"
 +    exit 1
 +fi
 +</code>
 +
 +and use it inside loop:
 +<code bash>
 +for tool in awk bc sed; do
 +    ....
 +done
 +</code>
  
 ===== Output ===== ===== Output =====
Line 103: Line 127:
 <code bash> <code bash>
 # Works correctly if script is sourced from another one # Works correctly if script is sourced from another one
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "$BASH_SOURCE[0]" )" && pwd )"+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 </code> </code>