Last active
July 14, 2020 20:58
-
-
Save boo1ean/5618604 to your computer and use it in GitHub Desktop.
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 string into array | |
# SPLITTED_ARRAY is a global array to store split result | |
# | |
# Usage example: | |
# | |
# split "1,2,3", "," | |
# result=0 | |
# for i in ${SPLITTED_ARRAY[*]} | |
# do | |
# result=$(($result + $i)) | |
# done | |
# | |
# Will output "6" | |
declare -a SPLITTED_ARRAY | |
function split { | |
local OLDIFS=$IFS | |
IFS=$2 | |
SPLITTED_ARRAY=() | |
for i in $1 | |
do | |
SPLITTED_ARRAY+=($i) | |
done | |
IFS=$OLDIFS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment