Register
It is currently Fri Jul 25, 2014 5:19 am

How do I know which shell I am running ?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Sun May 15, 2005 11:06 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
Question: How do I know which shell I am running ?

The Answer is :
Code:
echo $SHELL


you should get back a result that looks like:

Code:
/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........... :)


Top
 Profile WWW  
 PostPosted: Wed Jul 25, 2007 11:48 am   

Joined: Wed Jul 25, 2007 11:45 am
Posts: 11
crouse wrote:
Question: How do I know which shell I am running ?

The Answer is :
Code:
echo $SHELL


you should get back a result that looks like:

Code:
/bin/bash


Not completly true.

Code:
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:
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.


Top
 Profile  
 PostPosted: Mon Aug 24, 2009 8:06 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
well, from the prompt, the better way is to ask:
Code:
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...


Top
 Profile  
 PostPosted: Fri Sep 25, 2009 8:21 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
slacker_nl wrote:
crouse wrote:
Question: How do I know which shell I am running ?

The Answer is :
Code:
echo $SHELL


you should get back a result that looks like:

Code:
/bin/bash


Not completly true.

Code:
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:
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 ;)


Top
 Profile WWW  
 PostPosted: Tue Mar 23, 2010 12:37 pm   

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


Top
 Profile  
 PostPosted: Fri Nov 11, 2011 5:18 pm   

Joined: Thu Nov 10, 2011 7:31 pm
Posts: 21
If you take a closer look, it assigns many shells

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
syslog:x:101:103::/home/syslog:/bin/false
messagebus:x:102:105::/var/run/dbus:/bin/false
avahi-autoipd:x:103:108:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false
avahi:x:104:109:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
usbmux:x:105:46:usbmux daemon,,,:/home/usbmux:/bin/false
gdm:x:106:114:Gnome Display Manager:/var/lib/gdm:/bin/false
speech-dispatcher:x:107:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh
kernoops:x:108:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
pulse:x:109:116:PulseAudio daemon,,,:/var/run/pulse:/bin/false
rtkit:x:110:119:RealtimeKit,,,:/proc:/bin/false
hplip:x:111:7:HPLIP system user,,,:/var/run/hplip:/bin/false
saned:x:112:121::/home/saned:/bin/false
denton:x:1000:1000:denton,,,:/home/denton:/bin/bash


Top
 Profile  
 PostPosted: Sat Nov 12, 2011 4:16 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
blendmaster345 wrote:
If you take a closer look, it assigns many shells

However close I look, I see just one shell per user.


Top
 Profile  
 PostPosted: Sun Nov 13, 2011 1:31 pm   

Joined: Thu Nov 10, 2011 7:31 pm
Posts: 21
choroba wrote:
blendmaster345 wrote:
If you take a closer look, it assigns many shells

However close I look, I see just one shell per user.

That's what I meant, not that it assigns more than one shell to a user, just many shells to many users.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP