- How can I find my shell version using a Linux command?
- Solution 3
- How do I find the version of bash I am running?
- 7 Answers 7
- How can I find my shell version using a Linux command?
- 4 Answers 4
- How to Find My Shell Version Using a Linux Command
- How can I find my shell version using a Linux command?
- How to determine the current interactive shell that I’m in (command-line)
- How can I tell which Unix shell I am using?
- See version of Operating System in shell unix
- Shell script to verify the version of make on linux
- What shell am I in?
- How to get linux version set in shell script?
- Which shell I am using in mac
- How do I see see version of tcsh that is running?
How can I find my shell version using a Linux command?
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 $ZSH_VERSION echo $ZSH_PATCHLEVEL # shows more detailed information
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:
Solution 3
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.
$ sh -c './whatshell.sh' ash (Busybox 1.x) $ bash -c './whatshell.sh' bash 4.4.19(1)-release
$sh -c './whatshell.sh' bash 3.00.15(1)-release
~> 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)
~> 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.
How do I find the version of bash I am running?
(learning bash) I was trying to check the bash version so I typed /bin/bash -v . That outputted a whole lot of text to the screen (contents of .bashrc, and other files sourced from it). Could I have screwed up something (like overwriting some config files/setting incorrect environment variables etc.) due to that command? I also can’t find documentation on what the -v switch is for.
If you ran bash -v you invoked a new bash shell with verbose mode activated, so you will see verbose output for further commands (at the very minimum you’ll see printf «\033]0;%s@%s:%s\007» «$
7 Answers 7
The -v parameter for bash stands for verbose, and instructs bash to print out as much information as possible about what it is doing. On startup, it will print out all the configuration it is reading in.
To print out the version information for bash, use bash —version .
Alternatively, if you’re already running a bash shell, you can output the content of the special BASH_VERSION variable. echo «$BASH_VERSION» . There’s also a special array (BASH_VERSINFO) containing each version number in separate elements. if ((BASH_VERSINFO[0] < 4)); then echo "Sorry, you need at least bash-4.0 to run this script." >&2; exit 1; fi
The problem with this method is you cannot be 100% sure that any script, symbolic link, or any other kind of mess up configuration, who changed any environment variable at login. As I answered below, Ctrl+x Ctrl+v will show you exactly the bash version you’re currently running, regardless of any environment variable.
It’s worth pointing out that this will tell you the version of which bash (located at /bin/bash on most systems), which may be different than the version that happens to be running in some prompt or script. (For example, a script started with #!/usr/local/bin/bash might use a different version). Other methods (documented in other answers) may also be helpful.
When running bash (e.g. from gnome-terminal ) you can check value of BASH_VERSION environment variable.
$ echo $BASH_VERSION 4.2.37(1)-release
If the value is empty, you are not running bash .
This is better than just running bash —version , because it confirms that you are currently running bash, not just that you have bash installed on your system.
Beware: A set BASH_VERSION does not ensure that you are running bash : export BASH_VERSION; csh -c ‘echo $BASH_VERSION $SHELL $shell’ , so $BASH_VERSION may be set in csh as well
@Tino well, you could do a $SHELL —version , but again SHELL might be overwritten (and all shell do not support the —version flag).
$BASH_VERSION is very strongly advised over $SHELL —version . Needing this on a Mac trying to make sure I’m not using the system’s bash over a package managed (up to date) bash has $SHELL=/bin/bash , but is correctly configured and running my desired version. Can’t give another upvote here, unfortunately.
There’s a key shortcut that instructs current shell information to show up:
display-shell-version (C-x C-v) Display version information about the current instance of bash.
This is the best choice if you have messed with environment variables.
No, everything is alright. From man bash :
It is just not as silent as usual. Try
The usual —version may give you too much multi-line boilerplate so what I am using is
@wjandrea This is different from Paweł Nadolski’s answer. It runs the command in a new bash shell. One way this is useful is that it doesn’t need the shell currently being used to be bash . Another is that, even in bash , it’s possible (though not good) to set BASH_VERSION to a different value. It can even be exported as an environment variable. Yet even after running export BASH_VERSION=foobar , the method given here works, since the new bash shell resets its own BASH_VERSION automatically before performing the parameter expansion that reads it.
@EliahKagan, in my updated & upgraded installed 16.04 LTS system installed from the 16.04.1 iso file, bash —version says 4.3.48(1)-release and apt-cache policy bash says 4.3-14ubuntu1.2 and I have checked that the executable bash file comes from the package ‘bash’. How should this be interpreted? There is a similar mismatch for usb-creator-gtk , and in that case the apt-cache output is correct. — Can we conclude that the higher version number is the correct one (and someone forgot to update the other one)?
@sudodus A program’s version number can be different from the version number of the APT package it comes in. That’s what you’re seeing here. 4.3.48. is the version of Bash, 4.3-14. is the version of the bash package.
How can I find my shell version using a Linux command?
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:
Notice that you could use some strange shell, even one which is not POSIX compliant (e.g. fish or es. ). You should know what shell you are using. If it is bash , indeed try bash —version . Or use your package management system ( dpkg -l bash on Debian or Ubuntu)
4 Answers 4
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 $ZSH_VERSION echo $ZSH_PATCHLEVEL # shows more detailed information
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:
How to Find My Shell Version Using a Linux Command
How can I find my shell version using a Linux command?
How to determine the current interactive shell that I’m in (command-line)
- There are three approaches to finding the name of the current shell’s executable: Please note that all three approaches can be fooled if the executable of the shell is /bin/sh , but it’s really a renamed bash , for example (which frequently happens). Thus your second question of whether ps output will do is answered with «not always«.
- echo $0 — will print the program name. which in the case of the shell is the actual shell.
- ps -ef | grep $$ | grep -v grep — this will look for the current process ID in the list of running processes. Since the current process is the shell, it will be included. This is not 100% reliable, as you might have other processes whose ps listing includes the same number as shell’s process ID, especially if that ID is a small number (for example, if the shell’s PID is «5», you may find processes called «java5» or «perl5» in the same grep output!). This is the second problem with the «ps» approach, on top of not being able to rely on the shell name.
- echo $SHELL — The path to the current shell is stored as the SHELL variable for any shell. The caveat for this one is that if you launch a shell explicitly as a subprocess (for example, it’s not your login shell), you will get your login shell’s value instead. If that’s a possibility, use the ps or $0 approach.
- If, however, the executable doesn’t match your actual shell (e.g. /bin/sh is actually bash or ksh), you need heuristics. Here are some environmental variables specific to various shells:
- $version is set on tcsh
- $BASH is set on bash
- $shell (lowercase) is set to actual shell name in csh or tcsh
- $ZSH_NAME is set on zsh
- ksh has $PS3 and $PS4 set, whereas the normal Bourne shell ( sh ) only has $PS1 and $PS2 set. This generally seems like the hardest to distinguish — the only difference in the entire set of environment variables between sh and ksh we have installed on Solaris boxen is $ERRNO , $FCEDIT , $LINENO , $PPID , $PS3 , $PS4 , $RANDOM , $SECONDS , and $TMOUT .
How can I tell which Unix shell I am using?
This often works across a range of shells.
See version of Operating System in shell unix
If you are using Linux you can see
This way you just can know the version if you known the distribution in this case Fedora.
but you can always try for a file *-release in the folder /etcShell script to verify the version of make on linux
You can only use test (aka [ ) to compare strings and integers, not versions like that. Here’s two questions that show you ways to compare versions:
- BASH comparing version numbers
- How compare two strings in dot separated version format in Bash?
What shell am I in?
I want something that has the same feel of uname , pwd , whoami . Just a plain utility with a simple output.
So apparently the conclusion is that the tool I want does not exist, and there’s no simple cross-platform way to go about this.
Some answers here work fine on Linux.
How to get linux version set in shell script?
VERSION=$(lsb_release -sr) or VERSION=$(/usr/bin/lsb_release -sr) with full path.
will store the release value in $VERSION. What error are you getting ??
Which shell I am using in mac
macOS’s Terminal allows you to specify the shell in its preferences. By default, it is set to use your login shell, but it looks like you’ve overridden it to use Bash.
In the General tab of Terminal’s preferences, set it to «Default login shell,» to prevent your login shell from being overridden:
Also, make sure the «Run command» checkbox is not checked in the Shell tab of your profiles’ settings:
How do I see see version of tcsh that is running?
Look at the version variable:
% echo $version
tcsh 6.14.00 (Astron) 2005-03-25 (i386-intel-linux) options wide,nls,dl,al,kan,sm,rh,color,filec