Requirements

requirements.bsh

A set of functions for determining if you meet the required versions.

meet_requirements
Arguments:

$1 - Version you are checking [$2…] - Version rules

  • Supports versions of any length, 1, 1.0, 1.0.0.0.0.0, etc…

  • Supports an alpha version after the last number, 1.0.2rc5

  • Supported version rules: * ==, =- Does version equal this version. 1 is the same as 1.0.0, but not 1.0.0p1 * != - Does the version not equal this version * < - Is this version less than this version * <= - Is this version less than or equal to this version * > - Is this version greater than this version * >= - Is this version greater than or equal to this version * or - All rules are and ed together, unless separated by an or, in which case a new group of and ed rules are started. Only one group has to be true for the result to be true. There is currently no support for rules more complex than this.

Example

meet_requirements 1.0.0 "<2.0.0" ">0.5.0"
meet_requirements 1.0.0 =1
meet_requirements 1.0.0 "<2.0.0" ">0.5.0" or ">3.0.0"
meet_requirements 3.1.0 "<2.0.0" ">0.5.0" or ">3.0.0"
version_eq

Checks to see if version $1 equals $2. Slightly more complex than a simple =. For example: 1.0p1 is the same as 1.0.0.0p1

Arguments:

$1 - LHS version $2 - RHS version

version_lt

Checks to see if version $1 is less than $2.

Arguments:

$1 - LHS version $2 - RHS version

version_gt

Checks to see if version $1 is greater than $2.

Arguments:

$1 - LHS version $2 - RHS version

split_version_string
Arguments:
  • $1 - Variable name to store the array in

  • $2 - The version string

Splits a version string up into its elements and stores them in an array.

Any values starting with a non-numerical character are optionally stored in the last element as pre-release/metadata (including leading/trailing whitespace).

Example:

$ split_version_string x "$(bash_version)"
$ declare -p x
declare -a x=([0]="5" [1]="0" [2]="11" [3]="r1")
split_version_string_and_remainder
Arguments:
  • $1 - Variable name to store the array in

  • $2 - Variable name to store leftover versioning information in (anything starting with a non-numeric character)

  • $3 - The version string

Splits a version string up into its elements and stores them in an array.

Any non-numerical values are stored in a separate variable as pre-release/metadata (including leading/trailing whitespace)