[net.unix-wizards] "$@ in shell"

andyc@tekecs.UUCP (Andy Crump) (08/19/83)

This is NOT a bug.  If you read the last line in the "Blank Interpretation"
section of the sh(1) manual page you will realize this is an intended
and documented feature and is NECESSARY for some shell scripts to work.

I strongly oppose any changes to bourne sh like this, especially when
it is documented.

Quote from sh(2):

	"... Implicit null arguments (those resulting from parameters
	that have no values) are removed."


Andy Crump
Tektronix Inc.
Engineering Computing Systems
Mail Stop 61-215
Wilsonville, Oregon, 97070

UUCP:	...!XXX!teklabs!tekecs!andyc (ignore return address)
	(where XXX is one of:aat, cbosg, chico, decvax, harpo, ihnss
	lbl-unix, ogcvax, pur-ee, reed, ssc-vax, ucbvax, zehntel)
CSNET:	tekecs!andyc @ tektronix
ARPA:	tekecs!andyc.tektronix @ rand-relay

laura@utcsstat.UUCP (Laura Creighton) (08/21/83)

Who is trying to change the Bourne shell?!? The original article never
made it here... Whoever it is...have a care for those of us who do
most of our programming in the shell. Consider what problems you would
have if 80% of the code you have produced in your whole life stopped
working -- including the tools you have for fixing broken shell scripts.

laura creighton
utzoo!utcsstat!laura (keep the weirdness in the Cshell, where i don't have
			to see it, please...)

dce@tekecs.UUCP (David Elliott) (08/21/83)

We here at Tektronix are "Committed To Changing The Bourne Shell".
(just kidding)

The original article noted that "$@" inside of a script does not
pass on null arguments. Example :

#!/bin/sh
# This script is called 'foo'.
a=0
for i in "$@"
do
	echo "$i"
	a=`expr $a + 1`
done
echo "Number of args is $a"


If you type 'foo a b c d e', you get
a
b
c
d
e
Number of args is 5

If you type 'foo a b c "" d e', you get
a
b
c
d
e
Number of args is 5

The original submitter said that they had changed 'ksh' (whatever the
hell that is. We have a ksh, too, but he couldn't have a copy of it)
and hoped that '6.0' sh would have this fixed.

Andy, the author of the article you saw and my boss, doesn't want
to change the shell. In fact, he's against it as much as you are.
(Neither of you are as adamant as I am, as I AM making some internal
mods to sh, which is my job.)

			David

laura@utcsstat.UUCP (Laura Creighton) (08/22/83)

Well, I have had many comments such as "why munge with the Csh?"
"But I **USE** the csh, munge the sh instead!".

Just what I expected. Pesonally, i hate the csh, but you notice that
I haven't hacked it. Now all of you folk who use the csh know the
terror I go through when someone mentions hacking the sh. I don't
want to cahnge the behavior of any highly used command such as the
shell unless it is fully upward compatible (for a start, I also
do not advocate the grafting on of useless features to any program).

laura creighton
utzoo!utcsstat!laura

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.

rjs@clyde.UUCP (08/22/83)

Previous articles have requested that no changes be made to sh since
there exists a large amount of code already written for it, some of which
might break.  This sort of attitude will cause the Unix* system to go
the route of FORTRAN, COBOL, and the IBM 370 architecture, namely it
will become obsolete due to stagnation.  I personally would like to see
the Unix system keep up with progress made in Computer Science and related
fields.  Although it shouldn't be changed at random and without warning,
it would be nice if at regularly scheduled intervals new releases were
put out which include changes that help make programs more readable, 
reliable, maintainable and all the other apple-pie 'able adjectives, or
which reduce the number of suprises a user may blunder into.  Keep the
Unix waters flowing.

	Robert Snyder
	{burl, floyd}!clyde!rjs

*Unix is a trademark of Bell Laboratories

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

scw@ucla-locus@cepu.UUCP (08/24/83)

From:  Steve Woods <cepu!scw@ucla-locus>


    In-Reply-To: clyde.105

    Previous articles have requested that no changes be made to sh since
    .
    .
    .
    Unix waters flowing.


I would much rather see a (semi)stagnant UNIX* that to have programs
suddenly break. There is a mechanism in UNIX to allow different shells;
if it is that important to someone to have $@ include "" args then haque
up sh and call it atsh or some such and make it be said users login shell.
Or vice versa (call sh osh).
*Flame on*
Contrary to popular belief IBM 370's, FORTRAN ,and COBOL are *NOT*
obsolete, rather they are still viable useful products with many years
of life ahead of them (30XXen and 43XXen are still 370 flavored machines).
Some people (poor benighted heathen) actually prefer to write COBOL,
and as everyone knows REAL PROGRAMMERS always write FORTRAN.
**FLAME DOUBLE**
One of the ***BIG*** problems with some operating systems is the regular
flow of new, often incompatable, and usually buggy releases.
*Flame off*

*UNIX iatoBL

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