Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminapetersen/d0b0758dfc84a1fff73987fed75ce895 to your computer and use it in GitHub Desktop.
Save benjaminapetersen/d0b0758dfc84a1fff73987fed75ce895 to your computer and use it in GitHub Desktop.
Parsing SemVer with Bash
#!/usr/bin/env bash
VERSION="$1"
VERSION="${VERSION#[vV]}"
VERSION_MAJOR="${VERSION%%\.*}"
VERSION_MINOR="${VERSION#*.}"
VERSION_MINOR="${VERSION_MINOR%.*}"
VERSION_PATCH="${VERSION##*.}"
echo "Version: ${VERSION}"
echo "Version [major]: ${VERSION_MAJOR}"
echo "Version [minor]: ${VERSION_MINOR}"
echo "Version [patch]: ${VERSION_PATCH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment