Cameron Simpson wrote:

>So you will find
>
>       ${1+"$@"}
>
>in portable wrapper scripts.
>
>Aside: ${1:+"$@"} is wrong wrong wrong. As an exercise, tell me what it would
>       break.

Hmm ... the latter construct would allow a null argument.  So to
demonstrate to myself how the behavior would differ, I created
args.sh:

#!/bin/bash
good=${1+"$@"}
bad=${1:+"$@"}
if [ -n "$good" ]; then echo "Good: $good"; fi
if [ -n "$bad" ] ;then echo "Bad: $bad"; fi

Then invoked it like this:

./args.sh "" one two

And lo, it did beget this:

Good:  one two

Which is interesting, and means that in the latter case, if the first
argument to the function happens to be null, they ALL get deep-sixed.
Thanks for the tip (and the challenge)!
-d

--
David Talkington
Prairienet / Community Networking Initiative
217-244-1962
[EMAIL PROTECTED]

PGP key: http://www.prairienet.org/~dtalk/dt000823.asc




_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to