How do I check my Bash version?

linux how to check bash version

Bash (Bourne Again Shell) is one of the most widely used command interpreters on Linux systems. Knowing the version of Bash installed on your system will be useful for various purposes (troubleshooting, optimizing scripts, monitoring system status, etc.).

This tutorial will guide you through several simple methods for checking the version of Bash on your Linux system, whether Debian, Ubuntu, Fedora, etc. The methods described in this article are also valid for checking the version of Bash with WSL (using Linux on Windows).

1. Using the bash command

The easiest way to check your Bash version is to use the following command in your terminal:

bash --version

When you run this command, you'll get an output that tells you the current version of Bash installed on your system. As you can see from the example below, we're using version 5.1.16(1).

GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Is this the latest version? To find out, check your distribution's documentation for the latest version available. This page gives information on the bash package for Debian.

2. Using the $BASH_VERSION variable

Another simple method is to use the built-in variable $BASH_VERSION. This variable, available natively on Linux, contains the version of Bash currently used by your shell. To display it, simply run this in the :

echo $BASH_VERSION

The output will show you the Bash version directly, in a more streamlined way than the previous method. Here's an example of the result:

5.1.16(1)-release

3. Checking with a script

You can also create a small shell script to check the version of Bash. This can be useful if you need to check this information regularly or as part of an automation process.

Create a new script file using the nano editor (or vi / vim):

nano ~/bash-version.sh

Add the following lines to the script:

!/bin/bash
echo "Bash version is $BASH_VERSION!"

Save the script and make it executable:

chmod +x ~/bash-version.sh

Run the script to display the version of Bash :

./bash-version.sh

Thanks to the use of echothis script will display the version of Bash used on your system directly in the console.

4. Conclusion

By reading this article from the Computer Tutorials box, you will have useful information for recovering the correct version of Bash on Linux.. As we've seen, there are several ways of checking the Bash version on your Linux system. Another method we haven't mentioned is to read the information contained in your machine's package manager (Aptitude on Debian, for example).

If you're interested in the subject of Bash scripts, here's a link to find out more and learn how to create your first script:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *