首页

Linux下查看使用的是哪种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