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.
#!/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
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.