BASH_VERSINFO

Built-in bash variables giving the running version: BASH_VERSION as a string and BASH_VERSINFO as an array of its parts.

In more detail

Element 0 of BASH_VERSINFO is the major version, so a script can refuse to run on bash 3 with a single arithmetic test. These variables describe the bash actually running the script, unlike running bash --version, which asks whichever bash comes first on your PATH.

Example

if ((BASH_VERSINFO[0] < 4)); then echo "needs bash 4" >&2; exit 1; fi

Related terms

Taught in

References