I was wondering whether subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",shell=True)
will be interpreted by sh
orzsh
instead of bash
in different server?
Anyone has ideas about this?
What should I do to make sure that it's interpreted by bash
?
To specify the shell, use the executable parameter with
shell=True
:Clearly, using the executable parameter is cleaner, but it is also possible to call bash from sh:
http://docs.python.org/2/library/subprocess.html
Note that /bin/sh is often symlinked to something different, e.g. on ubuntu:
You can use the
executable
argument to replace the default:You can explicitly invoke the shell of your choice, but for the example code you posted this is not the best approach. Instead, just write the code in Python directly. See here: mkdir -p functionality in Python