You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
870 B
870 B
Bash Tips
prevent last false
function body should not end up with a ternary statement
wrong last
Compound of 2 'false' statement returns false.
[[ : ]] && [[ : ]]
right last
[[ : ]] && [[ : ]] || true
arithmetic issue
last (++) statement does not complete successfully!
wrong ++
count=0
(( ++count )) # ok
(( ++count )) # last statement in function returns false
right ++
count=0
count=$((count+1))
properly grab $?
prefer plain
commandrather than! commandotherwise you will miss out the exit code
wrong if
if ! command; then
local code=$?
>&2 echo $code # => 0
fi
right if
if command; then
: # useful for preserving $?
else
local code=$?
>&2 echo $code
fi