I used to be able to do things like:X=123 cat <<EOFX is $XEOFor even simpler:X=123 echo $XThe first one still seems to work on Mac OS X after install the bash fix, however neither seem to work on my Ubuntu 14.04 instance in AWS anymore. What makes it that echo or cat no longer have access to these environment variables? Stranger still, when I pass the env vars to a NodeJS app I don't seem to have any issues:cat <<EOF > test.jsconsole.log('X is ' + process.env.X);EOFX=123 node test.jsThis seems to work in bash scripts as well:cat <<EOF > test.shecho X is \$XEOFchmod +x test.shX=123 ./test.sh
Did the shellshock bash fix break basic command line tools like echo and cat?
bash;shellshock
In any POSIX shell, when you writeX=123 echo $Xthe $X is expanded before the whole command is executed, i.e. if $X is initially unset, you get:X=123 echowhich is then executed. You can see more or less what the shell is doing with set -x:$ set -x$ X=123 echo X=$X+ X=123+ echo X=X=$ set +xYou can see that echo (actually the shell itself, which does the expansion before executing echo) still has access to the environment:$ X=123 eval 'echo $X'123The issue with cat <<EOF is similar. Note that concerning bash, there was a bug in old versions (before 4.1), described in the CHANGES file as:Fixed a bug that caused variable expansion in here documents to look in any temporary environment.This may be the cause of the behavior observed under Mac OS X. Do not rely on this bug.