Skip to content

Instantly share code, notes, and snippets.

@ksykulev
Last active December 11, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksykulev/4608420 to your computer and use it in GitHub Desktop.
Save ksykulev/4608420 to your computer and use it in GitHub Desktop.
Delimited String to Array
#!/bin/bash
str="a@b.com;b@c.com;d@e.com"
delimiter=";"
declare -a arr
arr=(`echo ${str//$delimiter/ }`)
#get "keys" - ${!arr[@]}
for i in "${!arr[@]}"; do
printf "%s\t%s\n" "$i" "${arr[$i]}"
done
#0 a@b.com
#1 b@c.com
#2 d@e.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment