Is this known to unix.wizards?
Arthur David Olson
ado at elsie.UUCP
Sat Jan 7 11:14:53 AEST 1989
In article <13307 at ncoast.UUCP>, allbery at ncoast.UUCP (Brandon S. Allbery) writes:
> 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+"$@"}
> . . .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.
I've attached the earliest mention of the idiom that I can find;
I don't recall how I first learned of it, but it's used in a number of scripts
here at elsie now (sccs work and carbon dating show December of '86 as the
earliest occurrence). Thanks to David Giacomo (or whomever) for the discovery!
--
UNIX is a registered trademark of AT&T.
--
Arthur David Olson ado at ncifcrf.gov ADO is a trademark of Ampex.
< Path: elsie!cvl!umcp-cs!seismo!ut-sally!pyramid!decwrl!sun!david
< From: david at sun.uucp (David DiGiacomo)
< Newsgroups: net.unix-wizards
< Subject: Re: Problems with System V Release 2.1 on 68010
< Message-ID: <3514 at sun.uucp>
< Date: 16 Apr 86 18:15:14 GMT
< References: <401 at oscvax.UUCP> <412 at hropus.UUCP>
< Reply-To: david at sun.uUCp (David DiGiacomo)
< Organization: Sun Microsystems, Inc.
< Lines: 18
<
< In article <412 at hropus.UUCP> ka at hropus.UUCP (Kenneth Almquist) writes:
< >> 4) Is it true that the sh construct "$@" (in a shell script) is supposed
< >> to be identically equal to the command-line arguments? It seems that
< >> it should, because otherwise there is no way to get at these because
< >> $@ = $* gets reparsed, and "$*" is one word.
< >> In our sh, "$@" is exactly equivalent to the command line args if there
< >> are some, otherwise it is equal to "" instead of nothing.
< >> Seems like a bug to me. If so, how wide-spread is it?
< >
< >It's on our SVR2 on a VAX here. The Korn shell gets this right, of course.
<
< This also afflicts SunOS 3.0. I find it incredibly annoying, but a simple
< workaround is to use ${1+"$@"} instead of plain "$@".
<
< [disclaimer]
< --
< David DiGiacomo {decvax, ihnp4, ucbvax}!sun!david david at sun.arpa
< Sun Microsystems, Mt. View, CA (415) 960-7495
More information about the Comp.unix.wizards
mailing list