My script sets some environment varrible, to be used by the Makefiles, so since every shell, bash(export to set varriable) and tcsh(setenv), I need to get the correct shell type, from where we have run the python, I have tried using $SHELL varrriable, but it always given me sh as my shell.
Is there a way, I can get the right shell type from a python script or will it always output "SH" as the $SHELL variable.
fish or . cshrc. Also you could run different script in background simple by starting a different shell. For example when using default system shell: running python use the system python (2.6 in my case) whereas changing shell running python will run the latest python (3.7) with access to non-default libraries, etc.
Use the following Linux or Unix commands: ps -p $$ – Display your current shell name reliably. echo "$SHELL" – Print the shell for the current user but not necessarily the shell that is running at the movement.
Python provides a Python Shell, which is used to execute a single Python command and display the result. It is also known as REPL (Read, Evaluate, Print, Loop), where it reads the command, evaluates the command, prints the result, and loop it back to read the command again.
Now, coming to the article's main subject, how will you know that you have bash or zsh? The answer is quite simple. Use the “–version” command to confirm the existence of both shells on your Linux system.
Sorry to bring this back from the dead but I just did this myself. The following should give you the path to your current shell:
from os import environ
print(environ['SHELL'])
You should be able to replace shell with any environment variable you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With