Created
July 22, 2021 11:20
-
-
Save mtracz/f4eda4131ca38bb88aed400e35ed2d47 to your computer and use it in GitHub Desktop.
bash: explode string into array by delimiter
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
| #!/bin/bash | |
| VERSION=1.2.3.4 | |
| oldIFS=$IFS | |
| # delimiter | |
| IFS="." | |
| #Read the split words into an array based on delimiter | |
| read -a VERSION_ARRAY <<< $VERSION | |
| IFS=$oldIFS | |
| VERSION_PATH="${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}.${VERSION_ARRAY[2]}" | |
| VERSION_MINOR="${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}" | |
| VERSION_MAJOR="${VERSION_ARRAY[0]}" | |
| echo VERSION_PATH=$VERSION_PATH | |
| echo VERSION_MINOR=$VERSION_MINOR | |
| echo VERSION_MAJOR=$VERSION_MAJOR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment