Skip to content

Instantly share code, notes, and snippets.

@geoffrepoli
Last active June 28, 2017 12:32
Show Gist options
  • Save geoffrepoli/c3fcb40f071d51a6c2ed847944e32184 to your computer and use it in GitHub Desktop.
Save geoffrepoli/c3fcb40f071d51a6c2ed847944e32184 to your computer and use it in GitHub Desktop.
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