Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/34ab6441a93eb85a91b2c30056659be0 to your computer and use it in GitHub Desktop.
Save abdennour/34ab6441a93eb85a91b2c30056659be0 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}"
@abdennour
Copy link
Author

use can use also `` :

major=$(echo $VERSION | cut -f1 -d".");
minor=$(echo $VERSION | cut -f2 -d".");
patch=$(echo $VERSION | cut -f3 -d".");
major_and_minor=$(echo $VERSION | cut -f1,2 -d".");

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