slacker_nl wrote:crouse wrote:Question: How do I know which shell I am running ?
The Answer is :
- Code: Select all
echo $SHELL
you should get back a result that looks like:
- Code: Select all
/bin/bash
Not completly true.
- Code: Select all
19:52 pts/4 0 wesleys@sinti:/home/wesleys$ bash
Linux sinti 2.6.17-11-generic #2 SMP Fri May 18 23:39:08 UTC 2007 i686 GNU/Linux
19:52:37 pts/4 0 wesleys@sinti:~$ echo $SHELL
/bin/zsh
19:52:39 pts/4 0 wesleys@sinti:~$
This is a better way:
- Code: Select all
running_shell=`ps -p $$ | egrep -v "PID|TTY|TIME|CMD" | awk '{print $NF}'`
# OSX processing
running_shell=`echo ${running_shell} | sed -e 's/-//g'`
# Unix/Linux processing
running_shell=`echo $running_shell | sed -e 's/(//g' -e 's/)//g'`
running_shell=`echo $running_shell | awk -F\/ '{print $NF}'`
This code is works for FreeBSD, Solaris, OSX and Linux and is tested with zsh/bash.
hmmmmmmm ok, this thread is pretty ancient, but echo $SHELL does indeed return the default shell, (NOT the version of bash, but your default shell, be it zsh,csh,bash,dash,sh, etc). your return of /bin/zsh is because you have zsh set to be your default shell in your .profile or .bashrc config file. echo $0 returns the running script name..... if the shell isn't running anthing else .. then it returns itself. Your better way, is what I'd call "overkill" ..... but to each his own
