Skip to content

Instantly share code, notes, and snippets.

@bitmvr
Last active January 6, 2024 14:02
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bitmvr/9ed42e1cc2aac799b123de9fdc59b016 to your computer and use it in GitHub Desktop.
Save bitmvr/9ed42e1cc2aac799b123de9fdc59b016 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}"
@andyfeller
Copy link

chefs kiss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment