With bash, I'm trying to set environment variables for a given command by injecting another variable before running said command:
It's easier to describe that with an example:
setHELLO="HELLO=42"
${setHELLO} echo ${HELLO}
I would expect this script to output 42
, instead I get an error line 2: HELLO=42: command not found
Precision: While here I could simply write
HELLO=42
echo ${HELLO}
I'm aiming to not provide all env variables to all commands in my shell script, which is why I'm setting the env variable explicitly right in the line where I run the command (echo ${HELLO}
)
I'm also aiming to not repeat the variable value declaration, by not re-declaring in front of each command like this:
HELLO=42; echo command1
HELLO=42; echo command2
HELLO=42; echo command3