Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #224879
| From | Greg Wooledge <wooledg@eeg.ccf.org> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: delimiters with more than one character? ... |
| Date | 2020-07-16 16:00 +0200 |
| Message-ID | <AtcAy-7x4-3@gated-at.bofh.it> (permalink) |
| References | <AtaIp-6p2-3@gated-at.bofh.it> <AtcAy-7x4-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Jul 16, 2020 at 03:52:01PM +0200, Thomas Schmitt wrote:
> I tried
>
> echo " 34 + 45 \| abc \| 1 2 3 \| c\|123abc " | \
> sed -e 's/\\|/\n/g' | \
> mapfile -t _S_AR
>
> with no visible effect on the array _S_AR. bash 4.3.30 and 5.0.11.
You can't use a pipeline, because each command in the pipeline runs in
a separate subshell.
> This works
>
> echo " 34 + 45 \| abc \| 1 2 3 \| c\|123abc " | sed -e 's/\\|/\n/g' >/tmp/x
>
> mapfile -t _S_AR < /tmp/x
Yes. Temp files are fine.
> A workaround without temporary file would be
>
> x=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "
> split=$(echo "$x" | sed -e 's/\\|/\n/g')
> end=$(echo -n "$x" | sed -e 's/./+/g')"+"
>
> mapfile -t _S_AR <<$end
> $split
> $end
No... just use the process substitution that I showed you already.
mapfile -t myarray < <(some command)
Do you need an actual demonstration?
unicorn:~$ f() { printf '%s\n' ' one ' 'two' 't h r e e'; }
unicorn:~$ mapfile -t a < <(f)
unicorn:~$ declare -p a
declare -a a=([0]=" one " [1]="two" [2]="t h r e e")
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
delimiters with more than one character? ... Albretch Mueller <lbrtchx@gmail.com> - 2020-07-14 15:00 +0200
Re: delimiters with more than one character? ... Alex Mestiashvili <amestia@rsh2.donotuse.de> - 2020-07-14 15:00 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-14 15:10 +0200
Re: delimiters with more than one character? ... Nicolas George <george@nsup.org> - 2020-07-14 15:10 +0200
Re: delimiters with more than one character? ... Alex Mestiashvili <amestia@rsh2.donotuse.de> - 2020-07-14 15:20 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-14 15:10 +0200
Re: delimiters with more than one character? ... Nicolas George <george@nsup.org> - 2020-07-14 15:20 +0200
Re: delimiters with more than one character? ... Nicolas George <george@nsup.org> - 2020-07-14 17:30 +0200
Re: delimiters with more than one character? ... Albretch Mueller <lbrtchx@gmail.com> - 2020-07-15 12:30 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-15 14:00 +0200
Re: delimiters with more than one character? ... David Wright <deblis@lionunicorn.co.uk> - 2020-07-15 14:30 +0200
Re: delimiters with more than one character? ... Bob Weber <bobrweber@gmail.com> - 2020-07-15 14:40 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-15 14:50 +0200
Re: delimiters with more than one character? ... Bob Weber <bobrweber@gmail.com> - 2020-07-15 16:20 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-15 16:30 +0200
Re: delimiters with more than one character? ... The Wanderer <wanderer@fastmail.fm> - 2020-07-15 16:30 +0200
Re: delimiters with more than one character? ... Nicolas George <george@nsup.org> - 2020-07-15 17:50 +0200
Re: delimiters with more than one character? ... Nicolas George <george@nsup.org> - 2020-07-15 15:10 +0200
Re: delimiters with more than one character? ... Bob Weber <bobrweber@gmail.com> - 2020-07-14 17:30 +0200
Re: delimiters with more than one character? ... Alessandro Baggi <alessandro.baggi@gmail.com> - 2020-07-15 17:30 +0200
Re: delimiters with more than one character? ... Eric S Fraga <e.fraga@ucl.ac.uk> - 2020-07-16 12:10 +0200
Re: delimiters with more than one character? ... "Thomas Schmitt" <scdbackup@gmx.net> - 2020-07-16 13:40 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-16 14:00 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-16 16:00 +0200
Re: delimiters with more than one character? ... Zenaan Harkness <zenaan@freedbms.net> - 2020-07-17 04:50 +0200
Re: delimiters with more than one character? ... Nicolas George <george@nsup.org> - 2020-07-17 10:50 +0200
Re: delimiters with more than one character? ... rhkramer@gmail.com - 2020-07-17 13:20 +0200
tmpfs is not a ramdisk (was: delimiters with more than one character? ...) Nicolas George <george@nsup.org> - 2020-07-17 13:30 +0200
Re: tmpfs is not a ramdisk (was: delimiters with more than one character? ...) David Wright <deblis@lionunicorn.co.uk> - 2020-07-17 18:20 +0200
Re: tmpfs is not a ramdisk (was: delimiters with more than one character? ...) rhkramer@gmail.com - 2020-07-17 20:30 +0200
Re: tmpfs is not a ramdisk (was: delimiters with more than one character? ...) Zenaan Harkness <zenaan@freedbms.net> - 2020-07-18 07:20 +0200
Re: tmpfs is not a ramdisk (was: delimiters with more than one character? ...) <tomas@tuxteam.de> - 2020-07-18 10:40 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-07-17 13:40 +0200
Re: delimiters with more than one character? ... "Thomas Schmitt" <scdbackup@gmx.net> - 2020-07-16 16:00 +0200
Re: delimiters with more than one character? ... Zenaan Harkness <zenaan@freedbms.net> - 2020-07-17 04:50 +0200
Re: delimiters with more than one character? ... Eric S Fraga <e.fraga@ucl.ac.uk> - 2020-07-16 15:00 +0200
Re: delimiters with more than one character? ... John Crawley <john@bunsenlabs.org> - 2020-08-05 08:30 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-08-05 15:10 +0200
Re: delimiters with more than one character? ... John Crawley <john@bunsenlabs.org> - 2020-08-06 05:00 +0200
Re: delimiters with more than one character? ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-08-06 13:40 +0200
Re: delimiters with more than one character? ... John Crawley <john@bunsenlabs.org> - 2020-08-07 03:10 +0200
csiph-web