Linux 有问必答:如何知道当前正在使用的 shell 是哪个?
问题: 我经常在命令行中切换 shell。是否有一个快速简便的方法来找出我当前正在使用的 shell 呢?此外,我怎么能找到当前 shell 的版本?
找到你当前正在使用的 Shell 版本
有多种方式可以查看你目前在使用什么 shell,最简单的方法就是通过使用 shell 的特殊参数。
其一,一个名为 "$$" 的特殊参数 表示当前你正在运行的 shell 实例的 PID。此参数是只读的,不能被修改。所以,下面的命令也将显示你正在运行的 shell 的名字:
$ ps-p $$
PID TTY TIME CMD
21666 pts/400:00:00bash
上述命令可在所有可用的 shell 中工作。
如果你不使用 csh,找到当前使用的 shell 的另外一个办法是使用特殊参数 “$0” ,它表示当前正在运行的 shell 或 shell 脚本的名称。这是 Bash 的一个特殊参数,但也可用在其他 shell 中,如 sh、zsh、tcsh 或 dash。使用 echo 命令可以查看你目前正在使用的 shell 的名称。
$ echo $0
bash
不要被一个叫做 $SHELL 的单独的环境变量所迷惑,它被设置为你的默认 shell 的完整路径。因此,这个变量并不一定指向你当前使用的 shell。例如,即使你在终端中调用不同的 shell,$SHELL 也保持不变。
$ echo $SHELL
/bin/shell
因此,找出当前的shell,你应该使用 $$ 或 $0,但不是 $SHELL。
找出当前 Shell 的版本
一旦你知道你使用的是哪个 shell,你可能想知道此 shell 的版本。为此,在命令行中输入 shell 并在后面加上 “--version” 参数可以查看版本信息。例如:
对于 bash shell :
$ bash--version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
Copyright(C)2013FreeSoftwareFoundation,Inc.
LicenseGPLv3+: GNU GPL version 3or later
Thisis free software; you are free to change and redistribute it.
Thereis NO WARRANTY, to the extent permitted by law.
对于 zsh shell:
$ zsh --version
zsh 5.0.7(x86_64-pc-linux-gnu)
对于 tcsh shell: $ tcsh --version
tcsh 6.18.01(Astron)2012-02-14(x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,nd,color,filec
对于某些 shell,你还可以使用 shell 特定的变量(例如,$BASHVERSION 或 $ZSHVERSION)。
$ echo $BASH_VERSION
4.3.8(1)-release
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。