Q:

Why doesn't `FOO=42 echo "$FOO"` print 42 in Bash?

I'm confused by this behaviour:
$ FOO=42 echo "$FOO"

$ FOO=42 && echo "$FOO"
42

I'm accustomed to using VARNAME=value cmd to specify environment variables for other commands, so I was surprised to discover it doesn't work when cmd is echo. This might have something to do with echo being a Bash built-in. Is this the case? If so, is using && the best way to specify environment variables for Bash built-ins?
Update: && is no good, as it results in the environment variables being set permanently, which I'm trying to avoid.

A:

It doesn't matter that echo is a built-in. The reason is that variables on the command line are evaluated before executing the command, they're not evaluated by the command. You could get the result you want with:
FOO=42 bash -c 'echo "$FOO"'

This starts a new shell to execute echo $foo. Since the argument to bash is in single quotes, the variable is not replaced by the original shell.

A:

The replacement happens before the command is executed:

$FOO is replaced with its current value.
echo "" is executed with $FOO set to 42.

Try:
FOO=42 sh -c 'echo "$FOO"'

