* handling of variables
@ 2005-02-01 11:57 Michael Prokop
2005-02-01 14:06 ` Stephane Chazelas
2005-02-01 14:10 ` Peter Stephenson
0 siblings, 2 replies; 6+ messages in thread
From: Michael Prokop @ 2005-02-01 11:57 UTC (permalink / raw)
To: zsh-users
Hello,
I'm just wondering about:
% zsh -f
% FOO=BAR /bin/echo "$FOO"
%
Why doesn't this work? Am I running out of coffee? :)
Of course the following works:
% ( FOO=BAR ; echo "$FOO" )
BAR
% FOO=BAR && /bin/echo "$FOO"
BAR
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
%
Can anyone please explain me what is happening here?
thx && regards,
-mika-
--
,'"`. http://www.michael-prokop.at/
( grml.org -» Linux for texttool-users and sysadmins
`._, http://www.grml.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: handling of variables
2005-02-01 11:57 handling of variables Michael Prokop
@ 2005-02-01 14:06 ` Stephane Chazelas
2005-02-01 14:10 ` Peter Stephenson
1 sibling, 0 replies; 6+ messages in thread
From: Stephane Chazelas @ 2005-02-01 14:06 UTC (permalink / raw)
To: zsh-users
On Tue, Feb 01, 2005 at 12:57:37PM +0100, 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? :)
[...]
Because that calls echo with FOO=BAR in its environment, it's
not echo that expands "$FOO", it's the shell.
You can do:
FOO=BAR eval '/bin/echo "$FOO"'
Here, it's eval that expands "$FOO", so it makes sense to put
FOO=BAR in its /environment/.
(note that with POSIX shells (and zsh in sh emulation), it's
FOO=BAR command eval '/bin/echo "$FOO"'
otherwise $FOO retains its value even after the eval).
--
Stéphane
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: handling of variables
2005-02-01 11:57 handling of variables Michael Prokop
2005-02-01 14:06 ` Stephane Chazelas
@ 2005-02-01 14:10 ` Peter Stephenson
2005-02-01 15:24 ` Bart Schaefer
2005-02-02 22:43 ` Michael Prokop
1 sibling, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2005-02-01 14:10 UTC (permalink / raw)
To: zsh-users
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@csr.com> 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.
**********************************************************************
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: handling of variables
2005-02-01 14:10 ` Peter Stephenson
@ 2005-02-01 15:24 ` Bart Schaefer
2005-02-01 16:40 ` Bart Schaefer
2005-02-02 22:43 ` Michael Prokop
1 sibling, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2005-02-01 15:24 UTC (permalink / raw)
To: zsh-users
On Feb 1, 2:10pm, Peter Stephenson wrote:
}
} > % zsh -f
} > % FOO=BAR BAR=FOO echo $FOO $BAR
} >
} > % FOO=BAR BAR=FOO echo $FOO $BAR
} > BAR
} > %
}
} This looks suspiciously like a bug.
I *think* (not yet sure) this is happening because during interpretation
of the assignments,
BAR=FOO echo $FOO $BAR
examines "echo" and decides it looks like a simple builtin command and
therefore should have variables restored afterwards, but
FOO=BAR BAR=FOO echo $FOO $BAR
examines "BAR=FOO" and fails to reach the same conclusion.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: handling of variables
2005-02-01 15:24 ` Bart Schaefer
@ 2005-02-01 16:40 ` Bart Schaefer
0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2005-02-01 16:40 UTC (permalink / raw)
To: zsh-users
On Feb 1, 3:24pm, Bart Schaefer wrote:
} Subject: Re: handling of variables
}
} I *think* (not yet sure) this is happening because [...]
Nope, that's not it.
I now think that exec.c:save_params() needs to copy the value returned
by ecrawstr() before storing it in the restore_p linked list, but I'm
not sure what kind of memory to copy it into or what ramifications that
has for restore_params().
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: handling of variables
2005-02-01 14:10 ` Peter Stephenson
2005-02-01 15:24 ` Bart Schaefer
@ 2005-02-02 22:43 ` Michael Prokop
1 sibling, 0 replies; 6+ messages in thread
From: Michael Prokop @ 2005-02-02 22:43 UTC (permalink / raw)
To: zsh-users
* Peter Stephenson <pws@csr.com> [20050201 15:51]:
> Michael Prokop wrote:
> > 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.
Thanks for explanation, Peter.
> > 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.
Ok. ;-)
Thanks also to Stephane for his explanation!
thx && regards,
-mika-
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-02-02 22:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-01 11:57 handling of variables Michael Prokop
2005-02-01 14:06 ` Stephane Chazelas
2005-02-01 14:10 ` Peter Stephenson
2005-02-01 15:24 ` Bart Schaefer
2005-02-01 16:40 ` Bart Schaefer
2005-02-02 22:43 ` Michael Prokop
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).