Bourne shell differences w.r.t functions?

Chet Ramey chet at cwns1.CWRU.EDU
Fri Sep 14 08:19:43 AEST 1990


In article <1990Sep13.163836.19937 at cs.umn.edu> rantapaa at cs.umn.edu (Erik E. Rantapaa) writes:
>In experimenting on various systems, I have found the following
>differences in the way /bin/sh handles functions:
>
>   * Some give functions their own private argument list.

Systems with /bin/sh based on the AT&T s5r3 /bin/sh.  This version of
the shell preserves the dollar variables around a series of function
calls.  The s5r3.2 /bin/sh also allows recursive functions.

Such systems include SunOS 4.0, SunOS 4.1, and systems derived from
s5r3.

Bash and ksh also give functions private argument lists.

>   * Some have arguments passed to functions overwrite the script's
>     argument list.

Systems with /bin/sh based on AT&T s5r2 /bin/sh.  Ultrix /bin/sh5,
SunOS 3.x /bin/sh, the BRL Bourne Shell, HP-UX 6.x and 7.x /bin/sh
among others.

>   * Some don't support functions at all.

Systems with /bin/sh based on the version 7 sh.  4.3 BSD, most
systems derived therefrom, Ultrix /bin/sh.

>If /bin/sh supports functions, which behavior is more common?

The practice of giving functions their own private argument lists,
and correctly saving and restoring the dollar variables around
function invocations is clearly the wave of the future.

>Also, does the fact that some Bourne shells don't support functions
>mean that I shouldn't use functions in scripts which I send out for
>general use?

Well, 4.3 BSD is really the only system left using the v7 sh.  4.4 BSD
will ship with a shell that supports functions (whether or not that
shell is bash is something to be decided later).  I belive that 4.3-reno
already does, but I do not have 4.3-reno.  Nevertheless, at least for the
time being, I would not ship scripts with functions for general use.

>Are replacements such as bash and ksh widely enough
>available so people can use them if they have a defective /bin/sh?

Bash is freely available, but version 1.05 (the currently distributed
version) has a number of bugs.  I have fixed all that I am aware of,
so 1.06 should be fairly stable when distributed.

ksh costs money.  This alone restricts its availability somewhat, but it
is quite widespread.

>Finally, what is the POSIX standard with regard to this?

The Posix standard mandates the `private argument list' behavior.

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



More information about the Comp.unix.shell mailing list