Skip to content

Latest commit

 

History

History
72 lines (56 loc) · 1.72 KB

README.md

File metadata and controls

72 lines (56 loc) · 1.72 KB

bash-shell-utilities

This repository contains reusable shell modules. They are designed to be included into other scripts.

Semanic Versioning Parsing and Comparing functions

The script follows the semantic versioning 2.0.0 specification.

shl_semver

vn_Parse

inputs
semanic-versioning-string result-array-name
returns
A string that contains an array declaration with 3 elements (version, prerelease, build)
use eval on the string to get the array into your scope
status codes
0 for success
1 for parsing error

Example:

        local _result _array _parts
        _array="$(vn_Parse "${_input}" "_parts")"
        _result=$?
        eval "${_array}"

vn_Compare

The compare function compares the version and if the prerelease exists then it gets compared to. The prelease field, by default, will be compared with case sensitivity.

inputs
semanic-versioning-string1 semanic-versioning-string2 [sensitive|insensitive]
returns
status codes only
0 - versions strings are equal
1 - version string 1 is greater than version string 2
2 - version string 1 is less than version string 2
254 - semantic versioning string parsing error
255 - Argument count is incorrect
    vn_Compare "$1" "$2"
    case $? in
        0) op='=';;
        1) op='>';;
        2) op='<';;
      254) op='~';;  # semantic versioning string parsing error
      255) op='!';;  # Argument count is incorrect
    esac

The test_shl_semver is the testing function where you can run and see examples.