[comp.unix.ultrix] Bug report for /bin/sh5 under ultrix 4.0

rouben@math9.math.umbc.edu (10/01/90)

The following short script produces incorrect results under ultrix 4.0:

--------- Begin Script -----------------------
#!/bin/sh5

dummy () {
echo This message from dummy
}

set Hello World

echo $1   # These lines
echo $2   # will echo "Hello World"

dummy

echo $1   # These lines
echo $2   # will echo blanks!! They shouldn't.

---------- End Script ---------------------

Notes:
    /bin/sh5 is ultrix's counterpart of /bin/sh in System V. Probably its 
most significant advantage from a programmer's point of view is its
function defining capability.  In the script above the function "dummy" is
defined to echo a string.  An unintended side-effect of the execution of
the function dummy is that it clears the shell variable $1 and $2.
This shell script executes correctly on Stardent 3000 which is a hybrid
BSD/SysV machine.

--
Rouben Rostamian                               Telephone: (301) 455-2458
Department of Mathematics and Statistics       e-mail:
University of Maryland Baltimore County        rostamian@umbc.bitnet
Baltimore, MD 21228,  U.S.A.                   rostamian@umbc3.umbc.edu

gwyn@smoke.BRL.MIL (Doug Gwyn) (10/01/90)

In article <4052@umbc3.UMBC.EDU> rouben@math9.math.umbc.edu () writes:
>An unintended side-effect of the execution of the function dummy is that
>it clears the shell variable $1 and $2.

Early versions of the Bourne shell with support for shell functions, for
example UNIX System V Release 2, also do this.  I don't know whether or
not this has been officially "fixed" in later versions of the Bourne
shell.  Some Bourne-compatible shells do seem to have it fixed.

chet@cwns1.CWRU.EDU (Chet Ramey) (10/01/90)

In article <4052@umbc3.UMBC.EDU> rouben@math9.math.umbc.edu () writes:
>The following short script produces incorrect results under ultrix 4.0:

It will produce incorrect results for any system whose Bourne shell is
derived from the one shipped with System V release 2.  This includes at
least the HP-UX /bin/sh, Ultrix /bin/sh5, and the SunOS 3.x /bin/sh.  These
shells keep only a single global list in which to store the positional
parameters, and function invocations overwrite this global list. 

The System V.3 /bin/sh has this fixed.  (So does bash, for that matter. :-)

Chet
-- 
Chet Ramey				``Levi Stubbs' tears run down
Network Services Group			  his face...''
Case Western Reserve University	
chet@ins.CWRU.Edu		

guy@auspex.auspex.com (Guy Harris) (10/02/90)

>Early versions of the Bourne shell with support for shell functions, for
>example UNIX System V Release 2, also do this.  I don't know whether or
>not this has been officially "fixed" in later versions of the Bourne
>shell.

The SunOS 4.0.3 Bourne shell does it right, and I don't remember fixing
it, so I assume the fix was picked up from the S5R3 or S5R3.1 Bourne
shell.