These shell scripts are designed to be included into other scripts to provide functionality that could be reused in many scripts
Go to file
starkandwayne-bot 92d446e1df Updating CODE_OF_CONDUCT.md 2019-01-15 15:32:43 -05:00
CODE_OF_CONDUCT.md Updating CODE_OF_CONDUCT.md 2019-01-15 15:32:43 -05:00
LICENSE initial commit 2016-09-21 16:42:38 -04:00
README.md Improved compare desciption 2016-09-26 09:01:48 -07:00
shl_semver added ability to do case insensitive compare 2016-09-25 23:31:09 -07:00
test_semver added ability to do case insensitive compare 2016-09-25 23:31:09 -07:00

README.md

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.