(a) 0.2.0-123-g9e17591
(b) 0.2.0-g9e17591
- How to get 0.2.0-123 and 0.2.0 respectively ?
- How to extract number 0 & 123 from "0.2.0-123-g9e17591" and 2 & 0 from "0.2.0-g9e17591"
1 Answer
You could use
$ IFS='-' read -ra PARTS <<< 0.2.0-123-g9e17591
$ echo ${PARTS[*]}to split the string into array PARTS, with - as a field separator, and then check the results.
Then you could proceed similarly with the first element of array PARTS
$ IFS='.' read -ra PARTS2 <<< ${PARTS[0]}
$ echo ${PARTS2[*]}Repeat the operation as needed.
Sources
2