if [ -n "$x" ]; then ... else ... fi
if [ -z "$x" ]; then ... else ... fi
if [ ${#x} -eq 0 ]; then ... else ... fi
# a= # [[ ${#a} -eq 0 ]] && echo yes || echo no yes # a=x # [[ ${#a} -eq 0 ]] && echo yes || echo no no # a=123 # [[ ${#a} -eq 0 ]] && echo yes || echo no no # a=0 # [[ ${#a} -eq 0 ]] && echo yes || echo no no
[[ -z "$a" ]] && echo Empty || echo NotEmpty [[ ! -z "$a" ]] && echo NotEmpty || echo Empty [[ -n "$a" ]] && echo NotEmpty || echo Empty
mytst(){ a=${1-whatever} echo $a }
# mytst whatever # mytst 1 1 # mytst 2 2 # mytst "" # mytst whatever # mytst If no arg is given set a to whatever If # mytst "If no arg is given set a to whatever" If no arg is given set a to whatever # mytst " " # mytst "" # mytst whatever #