子进程中shell = True中的shell是否意味着bash?


问题内容

我不知道是否subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",shell=True)会被解释shzsh代替bash在不同的服务器?

有人对此有想法吗?

我应该怎么做才能确保它被解释bash


问题答案:

http://docs.python.org/2/library/subprocess.html

On Unix with shell=True, the shell defaults to /bin/sh

请注意,/ bin / sh通常与不同的符号链接,例如在ubuntu上:

$ ls -la /bin/sh
lrwxrwxrwx 1 root root 4 Mar 29  2012 /bin/sh -> dash

您可以使用executable参数替换默认值:

…如果shell = True,则在Unix上,可执行参数为默认的/ bin / sh指定替换shell。

subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",
                shell=True,
                executable="/bin/bash")