LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-11-2008, 02:34 AM   #1
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Rep: Reputation: 30
what is the command to find the current shell type


hi
Is there a command to find which shell u r currently using.
 
Old 11-11-2008, 02:36 AM   #2
jdbeyers
LQ Newbie
 
Registered: Nov 2008
Posts: 9

Rep: Reputation: 0
Hi,

echo $SHELL

You can also have a lookat all the variables by running "env"
 
Old 11-11-2008, 08:27 AM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

Here is a script I use to show methods of displaying the name of the current shell:
Code:
#!/bin/sh

# @(#) s3       Demonstrate display of current shell.

## command "ps $$" produces something like:
#  19746 pts/1    S+     0:00 bash
#      1     2     3        4    5

echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) bash3 tcsh ksh zsh dash rc
set -o nounset
echo

echo " Typical results from command ps looks like the first; the"
echo " second may be needed on some systems (e.g. Solaris 10):"

bash <<'EOF'
ps $$

echo
ps | grep $$
EOF

echo
echo " Result of pipeline to isolate the name of the shell:"
bash <<'EOF'
ps $$ |
tail -1 |
sed 's/  */ /g' |
cut -d" " -f5
EOF

echo
echo " Results from various shells (note rc difference)"
echo " using these commands. The variable SHELL is rarely"
echo " updated to reflect the current shell:
 1) ps
 2) cat proc/\$$/cmdline (needs newline)
 3) echo \$SHELL
 4) env | grep -i shell
"
echo

echo " Expecting bash3"
bash3 <<'EOF'
ps $$
cat /proc/$$/cmdline
echo
echo $SHELL
env | grep -i shell
EOF

echo
echo " Expecting tcsh"
tcsh <<'EOF'
ps $$
cat /proc/$$/cmdline
echo
echo $SHELL
env | grep -i shell
EOF

echo
echo " Expecting ksh"
ksh <<'EOF'
ps $$
cat /proc/$$/cmdline
echo
echo $SHELL
env | grep -i shell
EOF

echo
echo " Expecting zsh"
zsh <<'EOF'
ps $$
cat /proc/$$/cmdline
echo
echo $SHELL
env | grep -i shell
EOF

echo
echo " Expecting dash"
dash <<'EOF'
ps $$
cat /proc/$$/cmdline
echo
echo $SHELL
env | grep -i shell
EOF

echo
echo " Expecting rc"
rc <<'EOF'
ps $pid
# cat /proc/$$/cmdline
cat /proc/$pid/cmdline
echo
echo $SHELL
env | grep -i shell
EOF

exit 0
Producing:
Code:
% ./s3

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
GNU bash 3.00.16(1)-release
tcsh 6.13.00
pdksh 5.2.14 99/07/13.2
zsh 4.2.4
dash - no version provided for /bin/dash.
rc 1.7.1

 Typical results from command ps looks like the first; the
 second may be needed on some systems (e.g. Solaris 10):
  PID TTY      STAT   TIME COMMAND
 1125 pts/2    S+     0:00 bash

 1125 pts/2    00:00:00 bash

 Result of pipeline to isolate the name of the shell:
0:00

 Results from various shells (note rc difference)
 using these commands. The variable SHELL is rarely
 updated to reflect the current shell:
 1) ps
 2) cat proc/$$/cmdline (needs newline)
 3) echo $SHELL
 4) env | grep -i shell


 Expecting bash3
  PID TTY      STAT   TIME COMMAND
 1134 pts/2    R+     0:00 bash3
bash3
/bin/tcsh
SHELL=/bin/tcsh

 Expecting tcsh
  PID TTY      STAT   TIME COMMAND
 1139 pts/2    S+     0:00 tcsh
tcsh
/bin/tcsh
SHELL=/bin/tcsh

 Expecting ksh
  PID TTY      STAT   TIME COMMAND
 1178 pts/2    S+     0:00 ksh
ksh
/bin/tcsh
SHELL=/bin/tcsh

 Expecting zsh
  PID TTY      STAT   TIME COMMAND
 1183 pts/2    S+     0:00 zsh
zsh
/bin/tcsh
SHELL=/bin/tcsh

 Expecting dash
  PID TTY      STAT   TIME COMMAND
 1188 pts/2    S+     0:00 dash
dash
/bin/tcsh
SHELL=/bin/tcsh

 Expecting rc
  PID TTY      STAT   TIME COMMAND
 1193 pts/2    S+     0:00 rc
rc
/bin/tcsh
SHELL=/bin/tcsh
Best wishes ... cheers, makyo
 
Old 11-11-2008, 08:44 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
A simple "echo $0" will let you know the name of the current shell as well. Or, more correctly speaking, the executable used to launch it, which should be enough info.

This alternative is unusable into a script (you'd get the name of the script in $0, of course).

Last edited by i92guboj; 11-11-2008 at 08:46 AM.
 
Old 11-11-2008, 11:06 AM   #5
penguinHugger
LQ Newbie
 
Registered: Aug 2008
Distribution: Ubuntu, EeeOS
Posts: 26

Rep: Reputation: 15
Smile

Code:
echo #SHELL
you can also use

Code:
help
but that will usually yield more info than you need.

 
Old 11-11-2008, 02:44 PM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi, penguinHugger.
Quote:
Originally Posted by penguinHugger View Post
Code:
echo #SHELL
you can also use
Code:
help
but that will usually yield more info than you need.
I think you will find that command help is a bash builtin, so if you are in a different shell, say tcsh, it probably won't work.

Also if you enter:
Code:
echo #SHELL
you will probably get a blank line ... cheers, makyo
 
  


Reply

Tags
current, name, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
command to temporary change current shell. hocheetiong Linux - Newbie 1 04-24-2008 01:07 PM
cpan> locate -u Unknown shell command 'locate -u'. Type ? for help. sharad2005 Linux From Scratch 1 08-04-2006 12:40 AM
shell command to find the number of collisions of NICs RajRed Linux - Newbie 14 04-19-2006 01:20 PM
How can I find if my processor type (x86) from the command line anuradha06 Linux - Software 3 12-15-2005 03:56 AM
problem with the shell command "find zosimus Linux - Software 7 06-14-2005 04:28 PM


All times are GMT -5. The time now is 06:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration