Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find my shell version using a Linux command?

Tags:

linux

shell

I would like to know about my shell version using a Linux command. I tried the following command, but it shows the type of the shell I am in.

Command:

echo $SHELL

Result:

/bin/bash
like image 394
sago Avatar asked Jul 07 '16 05:07

sago


3 Answers

This will do it:

$SHELL --version

In my case, the output is:

zsh 5.0.2 (x86_64-pc-linux-gnu)
like image 71
Muhammad Sumon Molla Selim Avatar answered Oct 26 '22 01:10

Muhammad Sumon Molla Selim


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. They're not necessarily the same.

For your default login shell, as the accepted answer says, $SHELL --version is likely to work. Most (but not all) shells accept a --version option. (dash does not.) And this assumes that the value of $SHELL hasn't been changed (there can be valid reasons to do so).

For the shell you're currently running, if it happens to be bash you can type:

echo $BASH_VERSION

For tcsh:

echo $version

For zsh:

echo $ZSH_VERSION
echo $ZSH_PATCHLEVEL # shows more detailed information

For ksh:

echo $KSH_VERSION

For 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. Printing $BASH_VERSINFO only prints the first element; to print all elements:

echo "${BASH_VERSINFO[@]}"
like image 35
Keith Thompson Avatar answered Oct 26 '22 03:10

Keith Thompson


There is a case when your shell does not have a command line parameter to determine the version directly. This case is Bourne shell. For Bourne shell I would recommend to use a script: 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.

Some examples:

Ubuntu 18.04

$ sh -c './whatshell.sh'
ash (Busybox 1.x)
$ bash -c './whatshell.sh'
bash 4.4.19(1)-release

CentOS 4

$sh -c './whatshell.sh'
bash 3.00.15(1)-release

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

~> 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.

like image 5
Alexander Samoylov Avatar answered Oct 26 '22 03:10

Alexander Samoylov