Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

print -C and terminators



On Sat, Jan 30, 2021 at 7:00 AM Beverly Pope <countryone77@xxxxxxxxx> wrote:
>
> On Jan 30, 2021, at 4:50 AM, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
>
> >  print -rC1 --
> >
> > This command doesn't print anything.
>
> % print -rC1 -- no_such_file(N)
>
> zsh 5.8 (Ubuntu): prints nothing
> zsh 5.7.1 (Mac): prints return

Hm; I get no output, in both cases.  Similarly on Centos (zsh 5.0).

This behavior seems like a bug to me.  Neither -n nor -N were
specified, so "print" should always output at least a newline.
However, it's been around for quite some time and obviously some
people know about it, so I suppose it should just be documented.  The
doc does make a very oblique reference to it under the -N option:
          print -rNC1 -- "$list[@]" is a canonical way to print an
          arbitrary list as null-delimited records.
The implication is that -C prevents the terminating NUL byte from
being printed when $list is empty.

ubuntu% print -rN -- | od -c
0000000  \0
0000001
ubuntu% print -rN -- 1 2 3 | od -c
0000000   1  \0   2  \0   3  \0
0000006
ubuntu% print -rNC1 -- | od -c
0000000
ubuntu% print -rNC1 -- 1 2 3 | od -c
0000000   1  \0   2  \0   3  \0
0000006

The related behavior of -n is a bit weird:

ubuntu% print -rnN -- | od -c
0000000
ubuntu% print -rnN -- 1 2 3 | od -c
0000000   1  \0   2  \0   3
0000005

This, however, is more questionable:

ubuntu% print -raNC1 -- 1 2 3 | od -c
0000000   1      \0   2      \0   3      \0
0000011

This explains the trailing spaces on the test case for globbing that I
posted a few days ago.    I sort of get why -a needs to do that when
the column count is >1, but it shouldn't be inserting trailing spaces
when the column count is 1.




Messages sorted by: Reverse Date, Date, Thread, Author