Objective
This article will provide you with the information on how to check bash version on your operating system.
Operating System and Software Versions
- Operating System: – Distribution Agnostic
Requirements
No special prerequisites are required is required.
Conventions
- # – requires given linux commands to be executed with root privileges either directly as a root user or by use of
sudocommand - $ – requires given linux commands to be executed as a regular non-privileged user
Instructions
Check Bash version using bash command
The easiest way to check bash version number is by executing the shell bash command with --version command option:
$ bash --version bash --version GNU bash, version 4.4.18(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later
From the above command bash command output we ca determine that the system’s bash version number is 4.4.18.
Check Bash version via builtin $BASH_VERSION variable
Another approach on how to check your shell’s bash version is to print the content of shell’s builtin variable $BASH_VERSION.
Example:
$ echo $BASH_VERSION 4.4.18(1)-release
Check Bash version from within shell script
Using the above builtin $BASH_VERSION variable example it is also possible to use/print bash version from within a bash shell script. Create a new new file called ~/check-bash-version.sh:
$ nano ~/check-bash-version.sh
Next, insert the following lines and save:
#!/bin/bash
echo "Checking for Bash version...."
echo "The Bash version is $BASH_VERSION !"
Once ready, make the file executable and run the script:
$ chmod +x check-bash-version.sh $ ./check-bash-version.sh Checking for Bash version.... The Bash version is 4.4.18(1)-release !
