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

using mapfile instead of read ( require v4 bash ) #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

elreydetoda
Copy link

So, first off this seems like a really awesome project 馃檪 I love me some bash 馃榿. So, thank you for making this. One of my friends linked to it for something they were doing 馃檪

Maybe there is another reason that you didn't use mapfile before, but since you are requiring v4+ anyways ( and mapfile was released in v4). Then I think this is a slightly less complex version of the same command. Maybe you were trying to be a bit more explicit for visual understanding of how things get split up ( setting IFS and everything ), but I get the same output when I run those example commands.

$ split() { mapfile -t arr <<< "${1//$2/$'\n'}";    printf '%s\n' "${arr[@]}"; }
$ split "apples,oranges,pears,grapes" ","
apples
oranges
pears
grapes
$ split "1, 2, 3, 4, 5" ", "
1
2
3
4
5

Let me know if there is anything I can do to help 馃檪 or if there is anything else I need to add ( tests, etc... ).
I look forward to looking more into this pure bash bible 馃榿

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

Successfully merging this pull request may close these issues.

None yet

1 participant