Why do the following examples from Arrow's reply output $var instead of 3?
I single quote or backslash $var as '$var' or \$var, hoping that
- first
$varwill be passed literally into the execution environment of the executable program/bin/echo, and - then inside the execution environment of the executable program
/bin/echo, the environment variablevar=3applies when parameter expansion happens on$var.
Why doesn't the parameter expansion happen inside the execution environment of the executable program /bin/echo? Note:
in the original shell,
$varis single quoted or backslashed, so should not be expanded in the execution environment of the original shell.the original shell removes the single quotes or backslash around
$var, and then passes$varand environment variablevar=3into the execution environment for running/bin/echo, so I think that parameter expansion of$varshould happen in the execution environment for running/bin/echo.
Note that I use set -x to print out the trace information, but can't figure out what is actually the result after expansion but before execution.
Thanks.
tim$ unset var $ set -x tim$ var=3 /bin/echo '$var' + var=3 + /bin/echo '$var' $var tim$ var=3 /bin/echo \$var + var=3 + /bin/echo '$var' $var $ var=3 exec /bin/echo \$var | cat + cat + var=3 + exec /bin/echo '$var' $var tim$ var=3 exec /bin/echo '$var' | cat + var=3 + exec /bin/echo '$var' + cat $var
/bin/echoknow or care about variable expansion? Variable expansion is a shell feature, not a property of the environment.