Re: Splitting in shell (bash)

Liste des GroupesRevenir à cu shell 
Sujet : Re: Splitting in shell (bash)
De : Lem (at) *nospam* none.invalid (Lem Novantotto)
Groupes : comp.unix.shell
Date : 10. Nov 2024, 01:51:58
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vgp03e$iqq$1@dont-email.me>
References : 1
User-Agent : Pan/0.160 (Toresk; )
Il Sat, 9 Nov 2024 16:19:17 -0000 (UTC), Kenny McCormack ha scritto:

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
     inherently dangerous.  Yes, I know it has been somewhat de-fanged
recently - but it is still dangerous.

Sorry to bother you, but... could you please give me some hints? Why
dangerous? Thanks. :-)
 
Anyway, the point of this thread is that I have recently developed a
good solution for this, using bash's "mapfile" command. 
[...]
mapfile -td ';' <<< "$foo"

Yes, mapfile is a good solution. Of course, when you use <<<, no word
expansion is performed, so IFS is out of the question.

Caveats:
    1) You can only have one, single character delimiter.

But you could have more using IFS. Something like:

| $ IFS=";:[ENTER]
| "
| $ declare myarray
| $ for i in $(echo "one:two;three 3[ENTER]
| four"); do myarray+=( $i ); done
| $ echo ${myarray[@]}
| one two three 3 four
| $ echo ${myarray[2]}
| three 3

What would be wrong with it?
--
Bye, Lem

Date Sujet#  Auteur
9 Nov 24 * Splitting in shell (bash)11Kenny McCormack
10 Nov 24 +* Re: Splitting in shell (bash)4Lem Novantotto
10 Nov 24 i`* Re: Splitting in shell (bash)3Lawrence D'Oliveiro
10 Nov 24 i +- Re: Splitting in shell (bash)1Lem Novantotto
17 Nov 24 i `- Re: Splitting in shell (bash)1Jerry Peters
10 Nov 24 `* Re: Splitting in shell (bash)6Kenny McCormack
10 Nov 24  `* Re: Splitting in shell (bash)5Axel Reichert
10 Nov 24   +* Re: Splitting in shell (bash)3Janis Papanagnou
10 Nov 24   i`* Re: Splitting in shell (bash)2Kenny McCormack
10 Nov 24   i `- Re: Splitting in shell (bash)1Janis Papanagnou
9 Dec 24   `- Re: Splitting in shell (bash)1Kenny McCormack

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal