How to Find My Shell Version Using a Linux Command

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

This will do it:

$SHELL --version

In my case, the output is:

zsh 5.0.2 (x86_64-pc-linux-gnu)

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

    1. echo $0 - will print the program name... which in the case of the shell is the actual shell.

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

    3. 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?

Try:

echo $0

This often works across a range of shells.

See version of Operating System in shell unix

If you are using Linux you can see

cat /etc/fedora-release

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 /etc

Shell 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?

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:

Terminal's settings

Also, make sure the "Run command" checkbox is not checked in the Shell tab of your profiles' settings:

Profile 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


Related Topics



Leave a reply



Submit