My goal is to add an argument to a program being executed if a bash variable is existent, as so:
bob -a some_arg (( if we have ${VAR} defined add '-b ${VAR}' as an argument ))
I'd like to avoid something like:
if [[ -z ${VAR} ]]; then
bob -a some_arg
else
bob -a some_arg -b ${VAR}
fi
Although, it is the only option?
Using bash parameter expansion :
bob -a some_arg ${VAR:+-b "$VAR"}
Some good doc : http://wiki.bash-hackers.org/syntax/pe
And also LANG=C man bash | less +/'Parameter Expansion'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With