🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #269

"$@" doesn't always work the same.

#269
From: Michael R. M. Cheselka
Date: Sun, 09 Aug 1992 05:12
78 lines
2099 bytes
In UNIX Shell Programming( revised edition, 0-672-48448-X), by Kochan and Wood, on pages
193-194, the following programming example is shown:

Script started on Sat Aug  8 23:47:22 1992
bash$ source ~/.bashrc
cactus: ~ $ cat >args
for arg in "$@"
do
   echo $arg
done
cactus: ~ $ chmod ug+x args
cactus: ~ $ set -x
cactus: ~ $ args a b c
+ args a b c
++ echo a
a
++ echo b
b
++ echo c
c
cactus: ~ $ args 'a b' c
+ args a b c
++ echo a b
a b
++ echo c
c
cactus: ~ $ cat > file
+ cat
a b c
cactus: ~ $ args `cat file`
++ cat file
+ args a b c
++ echo a
a
++ echo b
b
++ echo c
c
cactus: ~ $ cat > file
+ cat
'a b' c
cactus: ~ $ args `cat file`
++ cat file
+ args 'a b' c
++ echo 'a
'a
++ echo b'
b'
++ echo c
c
cactus: ~ $ exit
+ exit
exit

script done on Sat Aug  8 23:50:26 1992

Why is there a difference?!  How can there be a difference!  I notice it is
the same for sh as well.  I need to see if people have gotten accounts
created by using nawk to pull out names from a file in the form:
Firstname M. I. Lastname
Nextperson J. Random
...and on...

Then form a list in a file:
'Firstname M. I. Lastname' 'Nextperson J. Random' ...and on...

Use a for loop:

for arg in "@" ; do
grep $arg /etc/passwd | nawk -F: '{print $5 "\'s account has been created"}'
done

What is the correct way to do this?
-- 
cheselka@cactus.org         N5UVV          Michael R. M. Cheselka
os9@gnu.ai.mit.edu        (512)452-9412v ( 24hours answer. mach.)
membership@cactus.org Hangs out on 145.21mhz 400 W. 34th st. #103
{...}!cs.utexas!cactus.org!cheselka     Austin, Texas, 78705-1331
Technical Details
Message-ID: <1992Aug9.051242.1535@cactus.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cactus.ORG!cheselka

Show Full Headers
Complete Article Headers
Newsgroups: gnu.bash.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cactus.ORG!cheselka
From: cheselka@cactus.ORG (Michael R. M. Cheselka)
Subject: "$@" doesn't always work the same.
Message-ID: <1992Aug9.051242.1535@cactus.org>
Sender: gnulists@ai.mit.edu
Organization: Capital Area Central Texas UNIX Society, PO Box 9786, Austin, TX 78766-9786
Distribution: gnu
Date: Sun, 9 Aug 1992 05:12:42 GMT
Approved: bug-bash@prep.ai.mit.edu
Lines: 79