bash:变量定义环境变量

时间:2013-01-18 07:06:35

标签: bash environment-variables

在Bash,这项工作:

FOO=foo BAR=bar a_command

但如何使其有效?

ENV="FOO=foo BAR=bar"
$ENV a_command

我得到了:

FOO=foo: command not found

2 个答案:

答案 0 :(得分:3)

看看这是否有帮助:

  sh -c "$ENV a_command"

答案 1 :(得分:2)

这是env命令的用途

env $ENV a_command

请注意,您看到的行为是documented in the manual - 在扩展变量之前,shell会查找变量赋值