- What is Bash
- Bash is a shell program that enables you to pass commands to the operating system (in this case Linux) and have them executed
How does one check the version of the Bash shell
- 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.
- The Simple Approach
- The following command is the easiest way to know the bash version: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
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.shchmod +x check-bash-version.shNext, add the following lines to your script:#!/bin/bash echo”Checking the bash version….”echo “The Bash version is $BASH_VERSION !”
Now, check the bash version by running the script as follows:./check-bash-version.sh
Using the Shortcut KeyMeanwhile, 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:
From the Package Manager
- 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.shchmod +x check-bash-version.shNext, add the following lines to your script:#!/bin/bash echo”Checking the bash version….”echo “The Bash version is $BASH_VERSION !”
- The following command is the easiest way to know the bash version:bash –version
- 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)