Error Handling
Error Action
errexit: terminates on any non-zero exit code$?
sh
set -e # enable errexit
false # termination #
echo foo # unreachable1
2
3
4
5
2
3
4
5
${var:?ERROR}: throwERRORwhenvaris unset, terminates current execution.
sh
set --
local foo="${1:?argument required}"1
2
2
Value Fallback
If a variable is unset, there exist a way to fallback to another value inline.
sh
set --
local foo="${1:-default value}"
# like foo ??= 'default value' in other lang
echo "$foo" # default value1
2
3
4
2
3
4