Created
July 4, 2019 14:23
-
-
Save marcelomgarcia/ba29da78f9530ac065af1bce9e86ddcf to your computer and use it in GitHub Desktop.
bash split a string "a, b, c" into an array arr[a, b, c]
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
#!/usr/bin/env bash | |
# Split a string passed as parameter into array elements. | |
# "a, b, c" -> arr[a,b,c] | |
# https://stackoverflow.com/questions/10586153/split-string-into-an-array-in-bash | |
function splity { | |
IFS=', ' read -r -a array <<< "$1" | |
} | |
# Before splitting the string: | |
splity "$1" | |
for element in "${array[@]}" | |
do | |
echo "$element" | |
done | |
echo "have a nice day." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment