It is not hard to set a default variable in bash. E.g: How to write a bash script that takes optional input arguments?
But, these methods fail when using set -euxo pipefail
. What methods are compatible with the -u
flag?
Example:
set -euxo pipefail
foo=${2:test}
echo $foo
for Bash GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)