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

Re: handling of variables



Michael Prokop wrote:
> Hello,
> 
> I'm just wondering about:
> 
> % zsh -f
> % FOO=BAR /bin/echo "$FOO"
> 
> %
> 
> Why doesn't this work? Am I running out of coffee? :)

The sequence of interepretation is

line gets parsed to <environment-assignment> <command+args>
line gets expanded to /bin/echo "" (assuming FOO is currently empty)
shell forks
FOO=BAR is put in the environment
shell execs /bin/echo ""

Compare this with the result of

FOO=BAR printenv FOO

where the command itself examines the environment.

> And I'm wondering what's happening at:
> 
> % zsh -f
> % FOO=BAR BAR=FOO echo $FOO $BAR
> 
> % FOO=BAR BAR=FOO echo $FOO $BAR
> BAR
> %

This looks suspiciously like a bug.  The value of BAR is being restored
after the echo, but the value of FOO isn't.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited. 
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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