e36freak 1346084212 learn split_str() { local sep=$1 str=$2; split=(); while [[ $str = *"$sep"* ]]; do split+=("${str%%"$sep"*}"); str=${str#*"$sep"}; done; split+=("$str"); } # usage: split_str SEP STRING # splits STRING on the literal string SEP, populating the array "split". try: s='foo - bar - baz blah - quux'; split ' - ' "$s"; printf '%s\n' "${split[@]}" e36freak 1346084460 forget e36freak 1346084515 learn split_str() { local sep=$1 str=$2; [[ $1 && $2 ]] || return; split=(); while [[ $str = *"$sep"* ]]; do split+=("${str%%"$sep"*}"); str=${str#*"$sep"}; done; split+=("$str"); } # usage: split_str SEP STRING # splits STRING on the literal string SEP, populating the array "split". for example: s='foo - bar - baz blah - quux'; split_str ' - ' "$s"; printf '%s\n' "${split[@]}"