bash -c variable does not get assigned

后端 未结 1 1019
天命终不由人
天命终不由人 2021-01-17 05:10

I am trying to execute the following command:

 $ bash -c \"var=\'test\' && echo $var\"

and only an empty line is being printed.

相关标签:
1条回答
  • 2021-01-17 06:10

    Double quotes expand variables, so your command is expanded to

    bash -c "var='test' && echo"
    

    if $var is empty when you run it. You can verify the behaviour with

    var=hey
    bash -c "var='test' && echo $var"
    

    Switch the quotes:

    bash -c 'var="test" && echo $var'
    
    0 讨论(0)
提交回复
热议问题