How do I know which shell I am running ?

For different shells (other than bash).

How do I know which shell I am running ?

Postby crouse » Sun May 15, 2005 11:06 pm

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


...... on a side note..... make sure you CAPITALIZE the the word SHELL in the above command. Otherwise it will probably just return a blank line :D

yeah..... i did that ! Like 6 times in a row........... :)
User avatar
crouse
Site Admin
 
Posts: 561
Joined: Sun May 15, 2005 9:36 pm
Location: Des Moines, Iowa

Re: How do I know which shell I am running ?

Postby slacker_nl » Wed Jul 25, 2007 11:48 am

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.
slacker_nl
 
Posts: 11
Joined: Wed Jul 25, 2007 11:45 am

Re: How do I know which shell I am running ?

Postby Watael » Mon Aug 24, 2009 8:06 pm

well, from the prompt, the better way is to ask:
Code: Select all
echo $0
that will prompt the running program (i.e. the shell you're in)

...from a script, it's not been told to me, so I can't help, I'm still looking forward for forth...
Watael
 
Posts: 231
Joined: Mon Mar 02, 2009 3:03 am

Re: How do I know which shell I am running ?

Postby crouse » Fri Sep 25, 2009 8:21 pm

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 ;)
User avatar
crouse
Site Admin
 
Posts: 561
Joined: Sun May 15, 2005 9:36 pm
Location: Des Moines, Iowa

Re: How do I know which shell I am running ?

Postby Watael » Tue Mar 23, 2010 12:37 pm

default shell is 'assigned' in /etc/passwd, isn't it?
Watael
 
Posts: 231
Joined: Mon Mar 02, 2009 3:03 am


Return to Other Shells

Who is online

Users browsing this forum: No registered users and 1 guest