180

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

3
  • 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" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"). To end the verbosity, type exit command - you will be back in the original non-verbose bash shell (or whatever shell you were in).
    – ADTC
    Apr 5 '16 at 3:24
  • If you want the version of the "currently running" shell: stackoverflow.com/questions/3327013/…
    – Sohail Si
    Mar 29 at 9:13
  • How can I "link" another question here? (not just comment)
    – Sohail Si
    Mar 29 at 9:13
181

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.

6
  • Great! I also found the list of switches for bash.
    – Zabba
    May 2 '11 at 17:21
  • 39
    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
    – geirha
    May 2 '11 at 20:42
  • 3
    typo, should be something like [ "${BASH_VERSINFO}" -lt 4 ] or [ "${BASH_VERSINFO[0]}" -lt 4 ]
    – bufh
    Apr 22 '15 at 11:51
  • 1
    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.
    – vegatripy
    Jul 11 '17 at 8:53
  • 1
    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.
    – mkasberg
    Jun 6 '18 at 21:28
108

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.

5
  • 14
    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.
    – Flimm
    Apr 11 '13 at 9:23
  • 2
    +1 bash --version does not show the bash you are currently using.
    – gabeio
    Mar 6 '14 at 1:38
  • 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
    Nov 25 '14 at 19:48
  • @Tino well, you could do a $SHELL --version, but again SHELL might be overwritten (and all shell do not support the --version flag).
    – bufh
    Apr 22 '15 at 11:43
  • $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. Jan 9 '20 at 4:00
41

There's a key shortcut that instructs current shell information to show up:

Ctrl+x Ctrl+v

From man bash

   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.

8

No, everything is alright. From man bash:

   --verbose
          Equivalent to  -v.

It is just not as silent as usual. Try

--version 

instead.

2

The usual --version may give you too much multi-line boilerplate so what I am using is

bash -c 'echo $BASH_VERSION'
5
  • Duplicate of Pawel's answer
    – wjandrea
    Apr 1 '17 at 14:49
  • 5
    @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. Sep 28 '17 at 17:02
  • @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 bashsays 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
    Feb 21 '18 at 15:58
  • 1
    @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.
    – wjandrea
    May 25 '19 at 16:12
  • @EliahKagan I forgot to mention before, thanks for correcting me! I appreciate the knowledge.
    – wjandrea
    May 25 '19 at 16:14
1

To only get the version and not the multiline text:

$ bash --version | head -1 | cut -d ' ' -f 4
0

If you are on Windows and, instead, want to know what version of Git Bash you're running, it is part of Git for Windows.
So the Git Bash version is:

git --version

git version 2.23.0.windows.1

On my same machine when I run:

echo $BASH_VERSION

4.4.23(1)-release

To update to the latest version, generally you will want to download and install the latest version of git for Windows as per FAQ. Settings/customizations should be preserved if installed in the appropriate configuration folders.

3
  • Thanks Sheryl, but isn't this a Ubuntu forum?
    – Kurankat
    Mar 29 '20 at 23:13
  • Guess so. Sorry about that. I was looking for Git Bash, Google gave me this post, and I didn't pay attention to which StackExchange site I was on. I posted so I could find the information easily next time, as it took several tries to find even this post. Mar 30 '20 at 3:40
  • This is incorrect. git --version has nothing to do with Bash, regardless of whether you run it from a command prompt or the Bash emulator that ships with Git for Windows. "Git Bash" is a collection of POSIX utilities compiled against Windows, one of which is Bash. The terminal (think Terminal.app on MacOS) is mintty. Looks like getting Bash version is the same on the emulator as on a Unix machine. Please consider removing, editing, or proving me wrong. :D PS Win10 has a feature that enables you to run *nix utilities natively on Windows: superuser.com/a/1059340
    – Sinjai
    Jan 22 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.