Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.11 KB

README.md

File metadata and controls

40 lines (29 loc) · 1.11 KB

POSIX shell SemVer

A posix shell function that captures the fragments of the Semantic Versioning Specification. This repo also contains a short script that runs the function against a set of example version numbers to check its validity.

This uses only built-in POSIX shell commands. Think of it as an extension to the suggested regex FAQ entry for use in sh and other posix compliant shells.

Usage

#!/usr/bin/env sh

. "./semver.sh"

if semver "$1"; then
    echo "Major: $major";
    echo "Minor: $minor";
    echo "Patch: $patch";
    [ -n "$prerelease" ] && echo "Pre-release: $prerelease"
    [ -n "$buildmetadata" ] && echo "Build Metadata: $buildmetadata"
else 
    echo "No match found!";
fi 

Original Source

This repo came to life following a discussion in an issue in the semver repo on GitHub. See here. Forked from here which implements a version for bash.