Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Environment Passed to Functions



If an environment variable is set on the command line for a function, then 
that enviroment variable is only in effect for the first command in the 
function.  ksh handles this differently; the variable is in the environment 
for all the commands in the function.  E.g.

~ Wed 14 16:08 % echo $ZSH_VERSION 
2.6-beta9
~ Wed 14 16:12 % echo $LPDEST
 
~ Wed 14 16:13 % function foo {
> env >/dev/null
> env
> }
~ Wed 14 16:13 % LPDEST=foo foo | grep LPDEST
~ Wed 14 16:14 % 

LPDEST is not set.  Now for ksh:

~ Wed 14 16:15 % ksh
$ echo $LPDEST
 
$ function foo {
> env >/dev/null
> env
> }
$ LPDEST=foo foo | grep LPDEST
LPDEST=foo
$ 

I think the ksh behavior is more useful - it makes a function's environment 
more like a shell script's.  Opinions?

--Vin



Messages sorted by: Reverse Date, Date, Thread, Author