1
There's a trick available in bash allowing you to set environment variable for child process and run it in single line, retaining original values of variable in the shell. For example, in order to set the "LANG" and "FOO" environment variables and then run "gedit", we would use the following command (from Ubuntu docs):
LANG=he_IL.UTF-8 FOO=bar gedit
It doesn't work in zsh.
Is there a similarly simple alternative?
I was testing it with
TEST=5 echo $TEST
, but I've now discovered that it doesn't work neither in zsh nor in bash (outputs nothing). In zsh,echo
is builtin and it may explain why it doesn't work; however, what's wrong in case of bash? – Michael Pankov – 2013-02-11T16:37:08.6701I see. Read the Bash manual again: "words that the parser has marked as variable assignments (those preceding the command name) […] are saved for later processing – your
echo
command won't see the change of$TEST
. RunTEST=5 sh -c 'echo $TEST'
and see what happens! – slhck – 2013-02-11T18:51:33.897