dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Splitting a string on a delimiter

helpermethod opened this issue · comments

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 :-)