Is this known to unix.wizards?

Brandon S. Allbery allbery at ncoast.UUCP
Sun Jan 1 15:03:16 AEST 1989


Every so often there is mention of /bin/sh's braindamaged handling of "$@"
when there are no arguments.  I think I've worked out a way around it that
doesn't require "if" or "case":

				${1+"$@"}

The above construct should NOT be quoted.  And I'm pretty sure it will work
on all versions of the Bourne shell.  It seems to work in some tests I've
done here.  Anyone else want to comment?  I find it hard to believe that I'm
the first one to notice this, but I've never seen any discussion of it
anywhere and it *certainly* isn't in the manual or in any of the shell books
I've read.

(Analysis for non-wizards:  the construct ${variable+string} returns nothing
if the variable is not set and the value of string if the variable is set.
The string can be quoted and can include other variable substitutions.  If
this *is* the first time anyone's ever seen this particular trick, chalk it
up to the Bourne shell having *very* non-intuitive variable manipulations.)

++A somewhat surprised Brandon
-- 
Brandon S. Allbery, comp.sources.misc moderator and one admin of ncoast PA UN*X
uunet!hal.cwru.edu!ncoast!allbery		    ncoast!allbery at hal.cwru.edu
comp.sources.misc is moving off ncoast -- please do NOT send submissions direct
      Send comp.sources.misc submissions to comp-sources-misc@<backbone>.



More information about the Comp.unix.wizards mailing list