Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!xanth!nic.MR.NET!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon S. Allbery) Newsgroups: comp.unix.wizards Subject: Is this known to unix.wizards? Message-ID: <13307@ncoast.UUCP> Date: 1 Jan 89 05:03:16 GMT Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 25 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@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@.