With one environment variable it goes like:
bash$> foo=1 echo "$foo"
1
[EDIT: as noted below, even that won't work but worked only because $foo was previously set by some other trial. Should had given "unset foo" between trials.]
But what if one needs to set multiple environment variables in the same command line where the command is started? Like these don't work:
bash$> foo=1 bar=2 echo "$foo $bar"
1
bash$> foo=1 && bar=2 echo "$foo $bar"
1
bash$> (foo=1;foo=2) && echo "$foo $bar"
1
bash$> (foo=1 && foo=2) && echo "$foo $bar"
1
Is it possible? (with a script it is obvious)