[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trailing newlines disappear
From: |
Chet Ramey |
Subject: |
Re: Trailing newlines disappear |
Date: |
Fri, 9 Jun 2017 09:22:58 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 |
On 6/9/17 8:06 AM, Greg Wooledge wrote:
> Actually, it looks like the mapfile variant also has its own... let's
> call it "idiosyncratic" NUL handling:
>
> imadev:~$ unset a
> imadev:~$ mapfile -t a < <(printf 'foo\0bar\nbaz\nquux\n')
> imadev:~$ declare -p a
> declare -a a=([0]="foo" [1]="baz" [2]="quux")
>
> Where did "bar" go? Looks like mapfile loses the contents after a NUL
> byte within each line, but then subsequent lines are fine. (E.g. what
> you would get if you blindly called strcpy() for each line, with the
> source buffer possibly having multiple NULs.)
There's no mystery here. Mapfile reads lines delimited by newlines --
read(2) is happy to do that job. Shell variable values can't contain NULs;
they never have been able to. The entire line read gets stored as the
value, but since C strings are NULL-terminated, you just see the contents
preceding the first NUL. Should mapfile silently drop the NULs?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
- Re: Trailing newlines disappear, (continued)
- Re: Trailing newlines disappear, Peter & Kelly Passchier, 2017/06/08
- Re: Trailing newlines disappear, PePa, 2017/06/08
- Re: Trailing newlines disappear, Geir Hauge, 2017/06/08
- Re: Trailing newlines disappear, Peter & Kelly Passchier, 2017/06/08
- Re: Trailing newlines disappear, Greg Wooledge, 2017/06/08
- Re: Trailing newlines disappear, Eduardo Bustamante, 2017/06/08
- Re: Trailing newlines disappear, Peter & Kelly Passchier, 2017/06/08
- Re: Trailing newlines disappear, Greg Wooledge, 2017/06/09
- Re: Trailing newlines disappear,
Chet Ramey <=
- Re: Trailing newlines disappear, Greg Wooledge, 2017/06/09
- Re: Trailing newlines disappear, Chet Ramey, 2017/06/09
- Re: Trailing newlines disappear, L A Walsh, 2017/06/09
- Re: Trailing newlines disappear, Peter & Kelly Passchier, 2017/06/09
- Re: Trailing newlines disappear, Pierre Gaston, 2017/06/09
- Re: Trailing newlines disappear, Greg Wooledge, 2017/06/09
- Storing NUL in variables, George, 2017/06/09
- Re: Storing NUL in variables, Pierre Gaston, 2017/06/10
- Re: Storing NUL in variables, George, 2017/06/11
- Re: Trailing newlines disappear, Chet Ramey, 2017/06/12