문제

This command has an empty output.

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

Any idea, how can I define 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'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top