Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Splitting a string on a delimiter #120

Open
helpermethod opened this issue Jan 6, 2022 · 1 comment
Open

Splitting a string on a delimiter #120

helpermethod opened this issue Jan 6, 2022 · 1 comment

Comments

@helpermethod
Copy link

helpermethod commented Jan 6, 2022

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants