开发者

How to define environment variable in input command of su

This command has an empty output.

su user -c "ABC=abc;echo $ABC"

Any idea, how can I de开发者_StackOverflow中文版fine a variable in the input command?


Change your quotes to single quotes. The double quotes allow the variable to be substituted in the current environment where it's not set yet. To see the difference, try your version with $USER and compare it to this one:

su user -c 'ABC=abc; echo $ABC; echo $USER'


If using a bourne shell variant:

ABC=abc su user -c 'echo $ABC'

If not, use env.

env ABC=abc su user -c 'echo $ABC'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜