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; fiRelated terms
- Bash — The GNU shell: a program that reads commands, typed or from a script, and runs them.
- shell array — A variable that holds a numbered list of separate values, written in bash as names=(one "two words" three).
- arithmetic expansion — Evaluating whole-number maths inside $(( )) and replacing it with the result; (( )) on its own evaluates without printing anything.
Taught in
- Which Shell Am I In, And Getting Bash Five — Bash Scripting & Command Line Automation