BASH Programming

How to Check Bash Version

Checking the bash version helps Linux users in many cases, including troubleshooting and finding the currently available version in the system. If you are a regular bash user, it is good to check the bash version and keep it up to date as per the latest updates available. However, if you are a newbie in bash scripting, then you probably have never encountered a situation where you need to check the bash version.

So, in this guide, we will explain the simplest way to check the bash version in Linux. There are several ways you can easily check the bash version in your Linux system. Here, we will use multiple commands to learn the bash version of Ubuntu.

The Simple Approach

The following command is the easiest way to know the bash version:

bash --version

checking-bash-version

From the above result, you can see the current bash version of the system is 5.2.21(1).

Built in $BASH_VERSION variable

Another method to check the bash’s version is to enter the content of the bash shell’s variable as follows:

echo $BASH_VERSION

echo-to-check-the-bash-version

The Shell Script

It is also possible to check the bash version through a shell script. First, create a new shell script using the nano command, create a new bash file named check-bash-version.sh, and make it executable using the chmod command:

nano ~/check-bash-version.sh
chmod +x check-bash-version.sh

Next, add the following lines to your script:

#!/bin/bash echo
"Checking the bash version...."
echo "The Bash version is $BASH_VERSION !"

shell-scripting-to-check-the-bash-version

Now, check the bash version by running the script as follows:

./check-bash-version.sh

executing-the-shell-scripting

Using the Shortcut Key

Meanwhile, you can use the shortcut key ‘ Ctrl+X followed by ‘Ctrl+V’, and you may see the bash version on your screen as seen in the below image:

key-board-shortcut-key

From the Package Manager

Through the package manager, you can simply run a single command to view the bash version.

yum info bash (for CentOS/RHEL)
pkg info bash (for FreeBSD)
apk info bash (for Alpine Linux)
apt info bash (for Ubuntu)

apt-info-bash-scripting

Conclusion

So, this is how you can check the bash version through multiple approaches. If you are a new user and are not able to understand the CLI approaches, then we recommend that you use the shortcut keys to check the bash version. Moreover, you can also use the commands, but make sure to avoid typos, or else you may encounter errors while using them.

About the author

Prateek Jangid