what is the command to find the current shell type
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.