An example:
foo() {
for i in ${@+"$@"}; do
echo $i
done
}
I understand that ${parameter+word}
results in the expansion of word
if parameter
is set. But why not just use for i in "$@"; do
? I'm sure there is some benefit, but can anyone make an example?
Thanks!
According to the POSIX standard, "$@"
should expand to nothing if $@
is not set. However, the original Bourne shell expands this to a single empty string. ${@+"$@"}
will expand to nothing if $@
is not set in either shell.
Source: http://www.in-ulm.de/~mascheck/various/bourne_args/
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