Last active
May 30, 2020 18:59
-
-
Save chrisshroba/fb704b9545b98de85e251fa8bc3b037c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a sanity check to make sure we're parsing major, minor, patch versions correctly | |
➜ ~ echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/major=\1, minor=\2, patch=\3/g' | |
major=123, minor=456, patch=789 | |
# These parse out each of the parts | |
➜ ~ echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/g' | |
123 | |
➜ ~ echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/g' | |
456 | |
➜ ~ echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/g' | |
789 | |
# These set the shell variables | |
➜ ~ MAJOR_VERSION=$(echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/g') | |
➜ ~ MINOR_VERSION=$(echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/g') | |
➜ ~ PATCH_VERSION=$(echo 'abcdeef-v123.456.789 blah' | sed -E 's/.*-v([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/g') | |
# This one echoes the versions, and shows how to up the patch number. You need double quotes, not | |
# single, because single quotes cause bash variables to not be expanded. Using single quotes is | |
# good for the regexes above though so that special characters are not expanded by bash (like *!$) | |
➜ ~ echo "major=$MAJOR_VERSION, minor=$MINOR_VERSION, patch=$PATCH_VERSION" | |
major=123, minor=456, patch=789 | |
# Addition yay! | |
➜ ~ echo "next patch version=$MAJOR_VERSION.$MINOR_VERSION.$((PATCH_VERSION+1))" | |
next patch version=123.456.790 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment