zsh-workers
 help / color / mirror / code / Atom feed
* Environment Passed to Functions
@ 1995-06-14 20:17 Vinnie Shelton
  1995-06-15  8:46 ` P.Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Vinnie Shelton @ 1995-06-14 20:17 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Environment Passed to Functions
  1995-06-14 20:17 Environment Passed to Functions Vinnie Shelton
@ 1995-06-15  8:46 ` P.Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: P.Stephenson @ 1995-06-15  8:46 UTC (permalink / raw)
  To: Zsh hackers list

shelton@grind.ICD.Teradyne.COM wrote:
> 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.

Actually, the problem is slightly different: for shell functions and
builtins the parameter isn't put into the environment at all.  This
must be a bug.

It looks to me like the simplest thing is to export the variable for a
function, not for a builtin (the only two possibilities at that point
in the code).

*** Src/exec.c~	Mon Jun  5 10:34:30 1995
--- Src/exec.c	Thu Jun 15 09:43:27 1995
***************
*** 1416,1422 ****
  	    }
  	    
  	    if (cmd->vars) {
! 		addvars(cmd->vars, 0);
  		if (errflag) {
  		    lastval = 1;
  		    return;
--- 1416,1425 ----
  	    }
  	    
  	    if (cmd->vars) {
! 		/* Export this if the command is a shell function,
! 		 * but not if it's a builtin.
! 		 */
! 		addvars(cmd->vars, cn1->flags & SHFUNC);
  		if (errflag) {
  		    lastval = 1;
  		    return;

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-06-15  8:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-06-14 20:17 Environment Passed to Functions Vinnie Shelton
1995-06-15  8:46 ` P.Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).