Sujet : Re: Splitting in shell (bash)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shellDate : 10. Nov 2024, 06:55:31
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vgphsj$9p84$1@news.xmission.com>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vgo225$91aq$1@news.xmission.com>,
Kenny McCormack <
gazelle@shell.xmission.com> wrote:
...
First note/caveat: I'm not interested in any solution involving IFS, for
two reasons:
1) IFS-based solutions never work for me.
2) Changing IFS is inherently dangerous, because, well, IFS itself in
inherently dangerous. Yes, I know it has been somewhat de-fanged
recently - but it is still dangerous.
...
This works well, with a couple of caveats:
>
mapfile -td ';' <<< "$foo"
>
Caveats:
1) You can only have one, single character delimiter. It'd be nice if
you could have a reg-exp, like in GAWK.
2) If the output you're processing comes from a process, as is usually
the case, special care must be taken:
>
mapfile -td ';' < <(someprocess | awk 1 ORS=)
It occured to me after posting this that a somewhat simpler approach would
be to just convert all the delimiters to newlines, like this:
mapfile -t < <(someprocess | sed 's/;/\n/g')
-- 1) The only professionals who refer to their customers as "users" are computer guys and drug dealers.2) The only professionals who refer to their customers as "clients" are lawyers and prostitutes.