on-internet
← Community

Why can't I specify an environment variable and echo it in the same command line?

Stack Overflow ·

Consider this snippet: $ SOMEVAR=AAA $ echo zzz $SOMEVAR zzz zzz AAA zzz Here I've set $SOMEVAR to AAA on the first line - and when I echo it on the second line, I get the AAA contents as expected. But then, if I try to specify the variable on the same command line as the echo: $ SOMEVAR=BBB echo zzz $SOMEVAR zzz zzz AAA zzz ... I do not get BBB as I expected - I get the old value (AAA). Is this how things are supposed to be? If so, how come then you can specify variables like LD_PRELOAD=/... program args ... and have it work? What am I missing?

Comments

Sign in or sign up to comment and upvote.

No comments yet.