On Wed, Apr 06, 2016 at 04:26:52PM -0500, Derek Martin wrote: > Hi Cameron, > > On Wed, Apr 06, 2016 at 09:50:28AM +1000, Cameron Simpson wrote: > > Consider using ${1+"$@"}, which preserves quoting. > > How is this better than just "$@"? I believe it's non-portable (and > for that reason I'm less familiar with that syntax) but if I > understand correctly it expands like: > > if $1 is set use that, otherwise use "$@" (all arguments, individually > quoted) > > It seems as though this always evaluates to $1 (since if $1 is unset, > $@ is also necessarily empty)... which I think is not what is needed > here. Am I mistaken? I believe just "$@" (including the quotes) is > what you want here.
In the distant past constructions like that were needed because of a bug in the shells. If you had no arguments, "$@" was passed as "", a single null argument. Now it is correctly passed as no arguments. OT BTW I typically used ${@+"$@"} and playing with it after seeing this thread discovered a bug in handling it in ksh but not bash or zsh. Ksh only checks $1 for set/null rather than the entire list of args. jl -- Jon H. LaBadie j...@jgcomp.com 11226 South Shore Rd. (703) 787-0688 (H) Reston, VA 20190 (703) 935-6720 (C)