Last active
March 28, 2024 08:12
-
-
Save sandrock/5245d16a7d880e4662d2e1b3964850a2 to your computer and use it in GitHub Desktop.
bash parse semantic version
This file contains 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
#!/bin/bash | |
value=v1.20.03-xx7 | |
semver=$(echo "$value" | sed -r "s/^v?([0-9]+)\.([0-9]+)\.([0-9]+)(.*)$/\1 \2 \3 \4/") ; semver=( $semver ) | |
echo "result: ${semver[0]} ${semver[1]} ${semver[2]} ${semver[3]}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The sed command is used to set a space separator between each part. The
( )
generates an array composed of each part.