by codys · 10y ago · 0 comments
On point 3: `: ${FOO:-some default value}` is the typical pattern for ensuring a default value is set.
See http://mywiki.wooledge.org/BashFAQ/105 for some (most) of the pitfalls.
Or consider the last example from the wiki link above:
set -e
f() { local var=$(somecommand that fails); }
f # will not exit $ ( set -e; foo() { f=$(false); }; foo ; ); echo $?
1
$ ( set -e; foo() { local f=$(false); }; foo ; ); echo $?
0
$ ( set -e; foo() { local f; f=$(false); }; foo ; ); echo $?
1
However, it is still better to use -e to catch errors early.