Is there a subshell created when I run `sh -c “command”`, a new shell or none of these?

后端 未结 7 727
醉话见心
醉话见心 2020-12-08 23:18

In bash, when I run the following command:

sh -c \"command\"

is there created a subshell and then the command

7条回答
  •  一向
    一向 (楼主)
    2020-12-08 23:41

    Check this:

    $ name=foo
    $ echo $name
    foo
    $ sh -c "echo $name"
    foo
    $ sh -c 'echo $name'
    
    $ 
    

    You need ' in stead of " in your command. Else $name will get evaluated to foo before execution

    And to answer your question, yes, it does create/spawn a new shell.

提交回复
热议问题