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

Re: handling of variables



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



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