[btl.unix] "$@ in shell"

dgk@ulysses.UUCP (08/22/83)

I have received mail from a few who think that the Bourne shell is correct in
the expansion of "$@".  They rest their case on the line in the manual page
under Blank Interpretation, "Implicit null arguments ( those resulting from
parameter that have no values) are removed."
However, in the section on quoting it says that
"$@" is equivalent to "$1" "$2" ... .
If a shell script, script, consisting of the lines
	for i in "$@"
	do echo "$i"
	done
	for i in "$1" "$2" "$3"
	do echo "$i"
	done
is invoked as:
script 'line one' '' 'line three'
then the statement about quoting implies that the output should be:
line one

line three
line one

line three
The reason the rule on Blank Interpretation does not apply is the
$2 was an explicit null argument, not an implicit one.

guido@mcvax.UUCP (Guido van Rossum) (08/24/83)

We may all agree that a real bug was reported and that it should be fixed.
Please stop talking about it and let someone point out how to fix it!
-- 
Guido van Rossum, Mathematical Centre, Amsterdam, {philabs,decvax}!mcvax!guido

aeb@mcvax.UUCP (Andries Brouwer) (08/25/83)

I have the strong impression that the following fixes the $@ bug mentioned.

$ diff macro.c $S/macro.c
117,121c117,118
<                               THEN    LOOP IF !*v ANDF *id=='@'
<                                            THEN pushstak(QUOTE);
<                                            ELSE WHILE c = *v++
<                                               DO pushstak(c|quote); OD
<                                            FI
---
>                               THEN    LOOP WHILE c = *v++
>                                            DO pushstak(c|quote); OD


-- 
      Andries Brouwer -- Math. Centr., Amsterdam -- {philabs,decvax}!mcvax!aeb

mark@laidbak.UUCP (08/27/83)

How about "$@" when there are no arguments? The Bourne shell
turns this into one null argument. It probably ought to evaluate
into *no* arguments.

					Mark Brukhartz
					..!ihnp4!laidbak!mark