🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.bugs
Article #56

Re: /bin/sh $# bug with nested functions

#56
From: Chet Ramey
Date: Tue, 12 Jan 1993 18:35
43 lines
1851 bytes
In article <1993Jan12.160259.7994@bernina.ethz.ch> waldvoge@nessie.cs.id.ethz.ch (Marcel Waldvogel) writes:
$ Another nasty bug (which prevents me using 'shql' for now):
$ 
$ 	#!/bin/sh
$ 	nested_func(){
$ 	        echo "inside: $#"
$ 	}
$ 	func(){
$ 	        echo "before: $#"
$ 	        nested_func 6 7 8
$ 	        echo "after : $#"
$ 	}
$ 	func 1 2 3 4 5
$ 
$ gives the following output (on 2.1 and on 3.0):
$ 
$ 	before: 5
$ 	inside: 3
$ 	after : 3
$ 
$ Every other system I've tried returns
$ 
$ 	before: 5
$ 	inside: 3
$ 	after : 5
$ 
$ This is in accordance to what I expect from the behaviour of parameter passing.

The NeXT sh is based on the System V.2 sh (probably filtered through BRL,
though I don't know for sure).  The V.2 sh had the behavior you've observed
regarding $# and functions -- there was only a single array of arguments,
and it was overwritten each time a function was called.  The V.3 sh changed
that so that $# is saved and restored around each function call.  Posix.2
has standardized the V.3 (and ksh, and bash, and the new BSD sh, and ...)
behavior, but NeXT has not upgraded its version of sh. 

Chet

-- 
``The use of history as therapy means the corruption of history as history.''
	-- Arthur Schlesinger

Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu
Technical Details
Message-ID: <1iv30vINNe8q@usenet.INS.CWRU.Edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!spool.mu.edu!agate!usenet.ins.cwru.edu!odin!chet
References: <1993Jan12.160259.7994@bernina.ethz.ch>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!spool.mu.edu!agate!usenet.ins.cwru.edu!odin!chet
From: chet@odin.ins.cwru.edu (Chet Ramey)
Newsgroups: comp.sys.next.bugs
Subject: Re: /bin/sh $# bug with nested functions
Date: 12 Jan 1993 18:35:11 GMT
Organization: Case Western Reserve University, Cleveland OH (USA)
Lines: 43
Message-ID: <1iv30vINNe8q@usenet.INS.CWRU.Edu>
References: <1993Jan12.160259.7994@bernina.ethz.ch>
NNTP-Posting-Host: odin.ins.cwru.edu