LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what is the command to find the current shell type (http://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-command-to-find-the-current-shell-type-682561/)

babu198649 11-11-2008 02:34 AM

what is the command to find the current shell type
 
hi
Is there a command to find which shell u r currently using.

jdbeyers 11-11-2008 02:36 AM

Hi,

echo $SHELL

You can also have a lookat all the variables by running "env"

makyo 11-11-2008 08:27 AM

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

i92guboj 11-11-2008 08:44 AM

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).

penguinHugger 11-11-2008 11:06 AM

Code:

echo #SHELL
you can also use

Code:

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

:jawa:

makyo 11-11-2008 02:44 PM

Hi, penguinHugger.
Quote:

Originally Posted by penguinHugger (Post 3338432)
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


All times are GMT -5. The time now is 07:46 AM.