sh functions with "local variables"

Kenneth Almquist ka at cbnewsh.ATT.COM
Thu Jun 22 04:35:00 AEST 1989


>+>Now, in modern versions of sh (post SVR2, I think), function parameters
>+>are local to the function, but there's no way to have local variables
>+>otherwise.

Function arguments were made local in SVR3.

>+>Now, if the function doesn't have any arguments, or if you can use
>+>the arguments early and get rid of them, you can use "set" to put
>+>values in $1-$9, which is one way to have local variables.  Still,
>+>real local variables would be great.

I expect that POSIX (P1003.2) will include local variables, created
using the "local" builtin command.  Ash (which I recently posted to
comp.sources.unix) supports local variables.  Ksh also supports them,
using the "typeset" builtin.
					Kenneth Almquist



More information about the Comp.unix.wizards mailing list