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

Re: (LC_ALL=C; set -x 128 129; printf "%s\n" ${(#)@} | hexdump -C)



On Wed, Aug 30, 2023 at 12:28 AM Stephane Chazelas
<stephane@xxxxxxxxxxxx> wrote:
>
> $ zsh -c 'LC_ALL=C; set -x 128 129; printf "%s\n" ${(#)@} | hexdump -C'
> +zsh:1> printf '"%s\n"' ''
> +zsh:1> hexdump -C
> 00000000  22 0a 22                                          |"."|
> 00000003

This doesn't happen if you add +o multibyte:

+zsh:1> printf '%s\n' $'\M-\C-@' $'\M-\C-A'
+zsh:1> hexdump -C
00000000  80 0a 81 0a                                       |....|
00000004

Doc for (#) says:

     If the MULTIBYTE option is set and the number is greater than 127
     (i.e.  not an ASCII character) it is treated as a Unicode
     character.

> Does not happen without LC_ALL=C or with just "set -x 128" or with values <
> 128, or with printf "%s\n" $'\200' $'\201'

So $'\200' isn't subject to unicode interpretation where ${(#):-128}
is.  But this also doesn't happen with 2 separate arguments
${(#):-128} ${(#):-129}, only with ${(#)@}.  So something about the
implementation of $@ is mucking up the unicode translation, possibly
by leaving it thinking it's in the middle of an incomplete byte
sequence?  It's also different with double quotes around $@:

% zsh -fc 'LC_ALL=C; set -x 128 130; printf "%s\n" "${(#)@}" | hexdump -C'
+zsh:1> printf '"%s\n"' '"'
+zsh:1> hexdump -C
00000000  22 22 0a 22                                       |""."|
00000004




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