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
Next revisionBoth sides next revision
linux:bash [2021/04/02 16:55] niziaklinux:bash [2022/11/30 10:04] niziak
Line 1: Line 1:
 ====== Bash ====== ====== Bash ======
 +===== rerun as other user =====
 +
 +<code bash>
 +if [ $UID == 0 ]; then
 +    exec su -c "$0" fos4x
 +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>
  
 ===== Output ===== ===== Output =====
Line 102: Line 118:
  
 <code bash> <code bash>
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "$SOURCE" )" && pwd )"+# Works correctly if script is sourced from another one 
 +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 </code> </code>
  
 <code bash> <code bash>
 cur_file="${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}" cur_file="${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}"
-cur_dir="$(dirname "${cur_file}")+cur_dir="$(dirname "${cur_file}")"
 </code> </code>