🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1155

Re: Bourne shell differences w.r.t functions?

#1155
From: Bruce Adler
Date: Fri, 14 Sep 1990 19:21
34 lines
1811 bytes
In article <1990Sep13.221943.15220@usenet.ins.cwru.edu> chet@po.CWRU.Edu writes:
>In article <1990Sep13.163836.19937@cs.umn.edu> rantapaa@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@segue.com
ism.isc.com!segue!bruce
aero.org!segue!bruce
Technical Details
Message-ID: <3693@segue.segue.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!apple!usc!randvax!segue!bruce
References: <1990Sep13.163836.19937@cs.umn.edu> <1990Sep13.221943.15220@usenet.ins.cwru.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!apple!usc!randvax!segue!bruce
From: bruce@segue.segue.com (Bruce Adler)
Newsgroups: comp.unix.shell
Subject: Re: Bourne shell differences w.r.t functions?
Keywords: Bourne shell, /bin/sh, functions, ksh, bash, argument list, POSIX
Message-ID: <3693@segue.segue.com>
Date: 14 Sep 90 19:21:45 GMT
References: <1990Sep13.163836.19937@cs.umn.edu> <1990Sep13.221943.15220@usenet.ins.cwru.edu>
Reply-To: bruce@segue.segue.com (Bruce Adler)
Organization: Segue Software, Inc. - Santa Monica, CA. +1-213-453-2161
Lines: 34