pure-bash-bible
pure-bash-bible copied to clipboard
Splitting a string on a delimiter
A slightly nicer alternative to the proposed solution would be
split_string() {
# Usage: split_string "string" "delimiter"
printf '%s\n' "${1//$2/$'\n'}"
}
No need for creating an array first.
This is very nice, but it's a terrible name as it interferes with /usr/bin/split
, leading to hard-to-trace bugs. Please rename it to split_string
or somesuch :-)