Unexpected behavior in Bash

Posted by cYrus on Super User See other posts from Super User or by cYrus
Published on 2010-10-25T18:54:19Z Indexed on 2013/10/27 10:00 UTC
Read the original article Hit count: 402

Filed under:
|

From man bash:

A simple command is a sequence of optional variable assignments
followed by blank-separated words and redirections, and
terminated by a control operator. The first word specifies the
command to be executed, and is passed as argument zero. The
remaining words are passed as arguments to the invoked command.

So it's perfectly legal to write:

foo=bar echo $foo

but it doesn't work as I expect (it prints just a newline). It's quite strange to me since:

$ foo=bar printenv
foo=bar
TERM=rxvt-unicode
[...]

Could someone please explain me where I'm doing wrong?

© Super User or respective owner

Related posts about bash

Related posts about environment-variables