Bourne shell differences w.r.t functions?

Bruce Adler bruce at segue.segue.com
Sat Sep 15 05:21:45 AEST 1990


In article <1990Sep13.221943.15220 at usenet.ins.cwru.edu> chet at po.CWRU.Edu writes:
>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.

I don't think this is precisely correct.  Perhaps you meant that only 
the *positional* parameters are preserved around a function call.  The
*local* variables aren't preserved.

What does the following script do on your system:

	#!/bin/sh
	set -- yes
	lvar="yes"
	foobar() { lvar=$1; }
	foobar no
	echo positional variable $1, local varibale $lvar


My s5r3.2 based Bourne shell says positional yes, local no.  If your 
shell doesn't preserve local variables then it's difficult to implement
real recursive functions (i.e. a function that invokes itself).


-- 
bruce at segue.com
ism.isc.com!segue!bruce
aero.org!segue!bruce



More information about the Comp.unix.shell mailing list