歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Linux下查看使用的是哪種shell的方法匯總

Linux下查看使用的是哪種shell的方法匯總

日期:2017/3/1 17:55:16   编辑:SHELL編程

查看當前發行版可以使用的shell

復制代碼代碼如下:
[root@localhost ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin

查看當前使用的shell方法

一、最常用的查看shell的命令,但不能實時反映當前shell

復制代碼代碼如下:
[root@localhost ~]$ echo $SHELL
/bin/bash

二、下面這個用法並不是所有shell都支持

復制代碼代碼如下:
[root@localhost ~]$ echo $0
-bash

三、環境變量中shell的匹配查找

復制代碼代碼如下:
[root@localhost ~]$ env | grep SHELL
SHELL=/bin/bash

四、口令文件中shell的匹配查找

復制代碼代碼如下:
[root@localhost ~]$ cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/bash

五、查看當前進程

復制代碼代碼如下:
[root@localhost ~]$ ps
PID TTY TIME CMD
3052 pts/0 00:00:00 bash
3254 pts/0 00:00:00 ps

六、先查看當前shell的pid,再定位到此shell進程

復制代碼代碼如下:
[root@localhost ~]$ echo $$
1862
[root@localhost ~]$ ps -ef | grep 1862
root 1862 1860 0 01:50 pts/0 00:00:00 -bash
root 2029 1862 0 02:07 pts/0 00:00:00 ps -ef
root 2030 1862 0 02:07 pts/0 00:00:00 grep 1862

七、輸入一條不存的命令,查看出錯的shell提示

復制代碼代碼如下:
[root@localhost ~]$ asdf
bash: asdf: command not found

附:一條命令即可實現:

復制代碼代碼如下:
[root@localhost ~]$ ps -ef | grep `echo $$` | grep -v grep | grep -v ps
root 1862 1860 0 01:50 pts/0 00:00:00 -bash

Copyright © Linux教程網 All Rights Reserved