🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #1037

"$@" handled differently in bash and sh

#1037
From: Andy Bliven
Date: Thu, 14 Dec 1989 20:54
34 lines
1680 bytes
This is a bug that I posted to newsgroup gnu.util.bug: some netter rather
high-handedly (and incorrectly) told me to post it to gnu.bash.bug, but with
prompting sent along info pointing to this mail alias.

There is a difference in the way bash and sh handle "$@" in a function.  Here
is an example in sh:

    $ args () { for a in "$@"; do echo $a; done }
    $ args 1 2 3 4
    1
    2
    3
    4
    $

And the same example in bash:

    $ args () { for a in "$@"; do echo $a; done }
    $ args 1 2 3 4
    1 2 3 4
    $

Clearly the "$@" is NOT handled differently from "$*" in the latter example.
I'm running on a Sun 3/60 with Sun UNIX 4.2 Release 3.5, and the version is
"GNU bash, version 1.03.4".  After some experimentation I discovered that
eliminating the quotes is an acceptable workaround in my application, but if
your goal is 100% compatibility this is probably worth fixing.  It took me a
while to figure out just what was going wrong.

Andy Bliven
-------------------------------------------------------------------
Atherton Technology             mail:   bliven@atherton.com
1333 Bordeaux Drive                     phone:  408-734-9822
Sunnyvale, California 94089             fax:    408-744-1607
Technical Details
Message-ID: <oZW0Voz02QZ5RfkYRS@Atherton.COM>
Path: arc1-ca.pugleaf.net!utzoo!telly!philmtl!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!atherton.com!bliven

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!philmtl!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!atherton.com!bliven
From: bliven@atherton.com (Andy Bliven)
Newsgroups: gnu.bash.bug
Subject: "$@" handled differently in bash and sh
Message-ID: <oZW0Voz02QZ5RfkYRS@Atherton.COM>
Date: 14 Dec 89 20:54:12 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 34