Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!cmcl2!yale!husc6!rutgers!lll-crg!ames!ucbcad!ucbvax!jade!eris!mwm
From: mwm@eris.BERKELEY.EDU (Mike (Don't have strength to leave) Meyer)
Newsgroups: comp.sys.amiga
Subject: Re: Pattern Matching & documentation
Message-ID: <1967@jade.BERKELEY.EDU>
Date: Wed, 17-Dec-86 00:22:05 EST
Article-I.D.: jade.1967
Posted: Wed Dec 17 00:22:05 1986
Date-Received: Thu, 18-Dec-86 03:47:12 EST
References: <1908@jade.BERKELEY.EDU> <2306@sdcsvax.UCSD.EDU>
Sender: usenet@jade.BERKELEY.EDU
Reply-To: mwm@eris.BERKELEY.EDU (Mike (Don't have strength to leave) Meyer)
Organization: Missionaria Phonibalonica
Lines: 46

In article <2306@sdcsvax.UCSD.EDU> hutch@sdcsvax.UUCP (Jim Hutchison) writes:
>In article <1908@jade.BERKELEY.EDU> mwm@eris.BERKELEY.EDU (Mike (Don't have strength to leave) Meyer) writes:
>>	for i in $*
>>	do
>>		echo $i
>>	done
>consider this perhaps instead (sorry)...
>
>#! /bin/sh
>for i in $@
>do
>	echo $i
>done
>
>$@ is "$1" "$2" ...
>$* is  $1   $2  ...

Hmm - not quite. It should be "$@", not just plain $@. $@ (unqouted)
is identical to $* (unquoted). "$@" is what you described $@ as,
whereas "$*" is "$1 $2 $3 ... ".

In either case, it *STILL* doesn't work. If you feed your version an
unquoted '*', then the shell that I'm typing at (to invoke the command
script) will expand the '*'. If I quote it once (any of '*', "*" or
\*), then the shell strips off one level of quotes, which feeds it to
the for loop as "*", which feeds it to the echo as an unquoted '*',
where it gets expanded by the shell into a list of file names.

Note: We've just gotten baroque enough so that differences between
shells will start to show up, which is why I didn't mention the $@
mechanism before. ksh vs. SysV sh vs BSD sh vs earlier shells can (and
probably will) do different things. I should have expected someone
would know about $@, but not know that it still doesn't work, and just
started there. Of course, my apologies if your shell actually does the
right thing, and let me know which version of Unix you're running.

To top it off, the $@ mechanism hands back "" if you invoke the script
without any arguments. Makes for interesting things, especially if one
of the commands involved is a cd (anyone want to guess what a 'cd ""'
does? :-)

I hope the above provides sufficient proof that the Unix shell file
expansion mechanism is *NOT* simple, no matter what it may look like
to the casual user.