Last active
June 28, 2017 12:32
-
-
Save geoffrepoli/c3fcb40f071d51a6c2ed847944e32184 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
parse_array() { | |
FS=':' | |
key=(); val=() | |
for (( i=0 ; i < $(eval echo \${#$1[@]}) ; i++ )); do | |
key+=( "$(eval echo \${$1[$i]} | awk -F${FS} '{print $1}')" ) | |
val+=( "$(eval echo \${$1[$i]} | awk -F${FS} '{print $2}')" ) | |
done | |
} | |
# Assuming script contains myarray=( "key1:value1" "key2:value2" ) | |
parse_array myarray | |
myarray_key=( "${key[@]}" ) | |
myarray_val=( "${val[@]}" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment