Say I have a script doing:
some-command "$var1" "$var2" ...
And, in the event that
var1 is empty, I'd rather that it be replaced with nothing instead of the empty string, so that the command executed is:
some-command "$var2" ...
some-command '' "$var2" ...
Is there a simpler way than testing the variable and conditionally including it?
if [ -n "$1" ]; then some-command "$var1" "$var2" ... # or some variant using arrays to build the command # args+=("$var1") else some-command "$var2" ... fi
Is there a parameter substitution than can expand to nothing in bash, zsh, or the like? I might still want to use globbing in the rest of the arguments, so disabling that and unquoting the variable is not an option.