dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.
MIT License
36.41k stars 3.27k forks source link

Splitting a string on a delimiter #120

Open helpermethod opened 2 years ago

helpermethod commented 2 years ago

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.

plijnzaad commented 2 years ago

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