[nycbug-talk] nifty(1)
William Baxter
web-nycbug at superscript.com
Thu Dec 15 21:24:56 EST 2011
Excerpts from Matthew Story's message of Thu Dec 15 00:54:24 -0500 2011:
> i believe the most portable version is slightly uglier:
>
> On Dec 14, 2011, at 6:13 PM, Isaac Levy wrote:
>
> > shout() { echo "$0: $*" >&2; }
> > barf() { shout "$*"; exit 111; }
> safe() { ${1+"$@"} || barf "cannot $*"; }
> ^^^^^^^^ this bit is more reliable for sh on Solaris (real Bourne shell)
>
Delightful as the topic of Solaris compatibility may be I don't think it's worth
going that far. The ${1+"$@"} construct is indispensable for compatibility in
cases when an empty list is legitimate while an unintended empty argument is
not:
for ${1+"$@"}
versus
for "$@"
But an empty string and an empty list are both erroneous for safe(). While the
execution details may vary from shell to shell, I consider it a case of pilot
error to pass in either an empty argument or no argument to a function that
requires a program. A function cannot ultimately protect the caller from his
own error.
Cheers, W.
More information about the talk
mailing list