Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site hammer.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!harvard!talcott!panda!genrad!decvax!tektronix!orca!hammer!dce From: dce@hammer.UUCP (David Elliott) Newsgroups: net.bugs.usg Subject: System V.2 sh functions and parameter passing Message-ID: <1391@hammer.UUCP> Date: Thu, 18-Jul-85 12:58:13 EDT Article-I.D.: hammer.1391 Posted: Thu Jul 18 12:58:13 1985 Date-Received: Sun, 21-Jul-85 02:29:24 EDT Distribution: net Organization: Tektronix, Wilsonville OR Lines: 61 The documentation on functions in the System V.2 Bourne Shell is very sparse and is very vague on the point of parameter passing. The only documentation I could find was in the sh(1) manual page, and this says something like: when a function is executed, the positional parameters ($1, $2, ...) are set to the function arguments. This doesn't completely specify what really happens, since it doesn't actually define when a function is known to be a function. Take the following example: #!/bin/sh foo() { echo "$@" } echo "$@" foo a b c echo "$@" When executed with the arguments "x y z", the results are x y z a b c a b c This would imply that running "foo a b c" is the same as running the commands "set a b c; foo". When the line "foo a b c" is changed to "( foo a b c )", to run the function in a subshell, the results are x y z a b c x y z Which strengthens the assumption that the documentation means that the positional parameters are being set by the function execution and left. My questions: 1. Has anybody at AT&T worked on a method of parameter stacking or changing the shell so that the original parameter values are saved? (No, parameters can not be saved and restored by using code like: ARGS="$*" ... set $ARGS for obvious reasons, and it may not be possible to parse the entire argument list before a function execution is needed.) 2. Could someone at AT&T fully define the behavior of functions and put this in the documentation, or tell us where the behavior is defined? I'd hate to depend on the way functions currently work and then find a change made later. David Elliott {decvax|ihnp4}!tektronix!tekecs!dce