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:
ec
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[@]}"