🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.bugs
2 messages
2 total messages Started by Marcel Waldvogel Tue, 12 Jan 1993 16:02
/bin/sh $# bug with nested functions
#54
Author: Marcel Waldvogel
Date: Tue, 12 Jan 1993 16:02
28 lines
923 bytes
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.

-Marcel
Re: /bin/sh $# bug with nested functions
#56
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads