Just for kicks, here's an implementation of "if-then-else" called "ite", as a function. Note that:
1) It is pretty much a drop in for the missing functionality (in the usual ${var:X} syntax), when used inside $(). 2) All of the existing ${var:X} syntaxes are special cases of ite() and could be written in ite() instead. --- Cut Here --- # An implementation of a "if-then-else" for things like ${var-default value} # Usage: value=$(ite varname "if string" "else string") # If varname ends with a :, then use :+ instead of plain + for the test. ite() { [ $# = 3 ] || { echo "Wrong # of args ($#) - must be exactly 3!" >&2; return 1; } case $1 in *:) declare -n var=${1%?} || return; [ "${var:+x}" ] ;; *) declare -n var=$1 || return; [ "${var+x}" ] esac echo "${@:($?+2):1}" } --- Cut Here --- Sample usage: $ ite foo "foo is set to '$foo'" "foo is unset" $ ite foo: "foo is set to '$foo'" "foo is null or unset" ================================================================================= Please do not send me replies to my posts on the list. I always read the replies via the web archive, so CC'ing to me is unnecessary. When responding to my posts, please try to refrain from giving bureaucratic answers. If you have nothing useful to say, then just click Next and go on.