user2284570 user2284570 - 2 months ago 4x
Bash Question

Is there a way to change the SHELL program called by os.system()?

I’m in an embedded environment where

doesn’t exist so when I call
it always returns

Because of that environment, the
module isn’t available. I can’t create pipes too.

I’m using ɴᴀᴄʟ as glibc.

Setting the
environment variable doesn’t seems to work (it still tries to open

So is there a way to change the shell process invoked by


No, you can't change what shell os.system() uses, because that function makes a call to the system() C function, and that function has the shell hardcoded to /bin/sh.

Use the function instead, and set the executable argument to the shell you want to use:"command", shell=True, shell='/bin/bash')

From the Popen() documentation (which underlies all subprocess functionality):

On Unix with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell.


If shell=True, on Unix the executable argument specifies a replacement shell for the default /bin/sh.

If you can't use subprocess and you can't use pipes, you'd be limited to the os.spawn*() functions; set mode to os.P_WAIT to wait for the exit code:

retval = os.spawnl(os.P_WAIT, '/bin/bash', '-c', 'command')