Im using Ubuntu 20 with zsh. When I using subprocess.call, it always using bash to exec command but not zsh. How should I do to fix this?
Asked
Active
Viewed 1,457 times
1 Answers
1
No, it uses sh
regardless of which shell is your login shell.
There is a keyword argument to select a different shell, but you should generally run as little code as possible in a subshell; mixing nontrivial shell script with Python means the maintainer has to understand both languages.
whatever = subprocess.run(
'echo $SHELL',
shell=True, executable='/usr/bin/zsh',
check=True)
(This will echo your login shell, so the output would be /usr/bin/zsh
even if you ran this without executable
, or with Bash instead.)
In many situations, you should avoid shell=True
entirely if you can.

tripleee
- 175,061
- 34
- 275
- 318
-
For (much) more around this topic, see also https://stackoverflow.com/questions/4256107/running-bash-commands-in-python/51950538#51950538 – tripleee Jun 06 '21 at 09:01