I am using /bin/tcsh as my default shell.
However, the tcsh style command os.system('setenv VAR val') doesn't work for me. But os.system('export VAR=val') works.
So my question is how can I know the os.system() run command under which shell?
I am using /bin/tcsh as my default shell.
However, the tcsh style command os.system('setenv VAR val') doesn't work for me. But os.system('export VAR=val') works.
So my question is how can I know the os.system() run command under which shell?
These days you should be using the Subprocess module instead of os.system()
. According to the documentation there, the default shell is /bin/sh
. I believe that os.system()
works the same way.
Edit: I should also mention that the subprocess module allows you to set the environment available to the executing process through the env
parameter.
os.system()
just calls the system()
system call ("man 3 system
"). On most *nixes this means you get /bin/sh
.
Note that export VAR=val
is technically not standard syntax (though bash
understands it, and I think ksh
does too). It will not work on systems where /bin/sh
is actually the Bourne shell. On those systems you need to export and set as separate commands. (This will work with bash
too.)
If your command is a shell file, and the file is executable, and the file begins with "#!", you can pick your shell.
#!/bin/zsh
Do Some Stuff
You can write this file and then execute it with subprocess.Popen(filename,shell=True)
and you'll be able to use any shell you want.
Also, be sure to read this about os.system
and subprocess.Popen
.