The "colon sign" and the "dollar question mark" can be combined to check if a sh script does have an argument and assigns it directly to a variable of interest:
cmd=${1:? "Usage: $0 {build|upload|log}"} Can someone explain step for step how this works, and where I can find the details on its implementation? For example I would like to be able to call a function instead of printing to stderr.
help() { echo $"Usage: $0 {build|upload|log}" exit 1 } cmd=${1:? help} Why is this not possible?
test $1 && cmd=$1 || helpwhich would work. My question is really about how these built-in operators combine together in the way they do, not the specific result which can obtained in many ways.