[英]How can I find my shell version using a Linux command?
I would like to know about my shell version using a Linux command.我想使用 Linux 命令了解我的 shell 版本。 I tried the following command, but it shows the type of the shell I am in.
我尝试了以下命令,但它显示了我所在的 shell 的类型。
Command:命令:
echo $SHELL
Result:结果:
/bin/bash
This will do it:这将做到:
$SHELL --version
In my case, the output is:在我的情况下,输出是:
zsh 5.0.2 (x86_64-pc-linux-gnu)
It depends on whether you want to know the version of your default login shell, or the version of the shell you're currently running.这取决于您是想知道默认登录 shell 的版本,还是当前运行的 shell 版本。 They're not necessarily the same.
它们不一定相同。
For your default login shell, as the accepted answer says, $SHELL --version
is likely to work.对于您的默认登录 shell,正如公认的答案所说,
$SHELL --version
可能会起作用。 Most (but not all) shells accept a --version
option.大多数(但不是全部)shell 接受
--version
选项。 ( dash
does not.) And this assumes that the value of $SHELL
hasn't been changed (there can be valid reasons to do so). (
dash
没有。)而且这假设$SHELL
的值没有改变(这样做可能有正当的理由)。
For the shell you're currently running, if it happens to be bash
you can type:对于您当前正在运行的 shell,如果它恰好是
bash
您可以键入:
echo $BASH_VERSION
For tcsh
:对于
tcsh
:
echo $version
For zsh
:对于
zsh
:
echo $ZSH_VERSION
echo $ZSH_PATCHLEVEL # shows more detailed information
For ksh
:对于
ksh
:
echo $KSH_VERSION
For fish
:对于
fish
:
echo $version
Again, this assumes that the relevant variable hasn't been modified (there's rarely any non-malicious reason to change it).同样,这假设相关变量没有被修改(很少有任何非恶意的理由来改变它)。
Bash in particular has an array variable $BASH_VERSINFO
that gives more information in a form that's easier to process programmatically.特别是 Bash 有一个数组变量
$BASH_VERSINFO
,它以更易于编程处理的形式提供更多信息。 Printing $BASH_VERSINFO
only prints the first element;打印
$BASH_VERSINFO
只打印第一个元素; to print all elements:打印所有元素:
echo "${BASH_VERSINFO[@]}"
There is a case when your shell does not have a command line parameter to determine the version directly.有一种情况,您的 shell 没有命令行参数来直接确定版本。 This case is Bourne shell.
这个案例是Bourne shell。 For Bourne shell I would recommend to use a script: https://www.in-ulm.de/~mascheck/various/whatshell/whatshell.sh .
对于 Bourne shell,我建议使用脚本: https : //www.in-ulm.de/~mascheck/various/whatshell/whatshell.sh 。 The script is pretty small so that it is not a big trouble to review it and understand how it is working.
该脚本非常小,因此查看它并了解它是如何工作的并不是什么大问题。 I have tested this script inside different shells on Linux and Solaris and it always gave the shell version for me.
我已经在 Linux 和 Solaris 上的不同 shell 中测试了这个脚本,它总是为我提供 shell 版本。
Some examples:一些例子:
Ubuntu 18.04 Ubuntu 18.04
$ sh -c './whatshell.sh'
ash (Busybox 1.x)
$ bash -c './whatshell.sh'
bash 4.4.19(1)-release
CentOS 4 CentOS 4
$sh -c './whatshell.sh'
bash 3.00.15(1)-release
Solaris 10 Solaris 10
~> sh -c './whatshell.sh'
ksh88 Version (..-)11/16/88i (posix octal base)
~> bash -c './whatshell.sh'
bash 4.1.7(3)-release
~> csh -c './whatshell.sh'
SVR4 Bourne shell (SunOS 5 variant)
AIX 6.1 AIX 6.1
~> sh -c './whatshell.sh'
ksh88 Version (..-)11/16/88f
~> bash -c './whatshell.sh'
bash 4.2.0(1)-release
This is also answers for the question Bourne shell version which was marked as off topic.这也是被标记为题外话的Bourne shell version问题的答案。
Just use command只需使用命令
echo $BASH_VERSION回声 $BASH_VERSION
It must give you the version of shell.它必须给你 shell 的版本。 BASH_VERSION is the environment variable which contains version of shell.
BASH_VERSION 是包含 shell 版本的环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.