I understand the empty string in Bash is falsy, and we should be able to use something like
a=""
b=($a || 0)
which means if $a
is falsy, then just make it 0. But it gave
bash: syntax error near unexpected token `||'
and I understand we can use [-z $a]
and use the Bash ternary form:
a=""
[[ -z $a ]] && b=0 || b=$a
But is there a way to use something similar to the first form above that works in both Bash and Zsh?