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

Re: \M-^C vs \203 vs \x83 as visual representations of bytes



Wow; I had no idea Zsh printed out nonprintable characters that way. I concur that it would make sense to change, modulo backward compatibility considerations. Maybe a settable option?

 The M- "meta" syntax is something I associate with Emacs key-binding, and have rarely seen in other contexts.

On Sun, Feb 25, 2024 at 4:08 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
I guess \M-^C (or \M-\C-C) as the representation of 0x83 made
sense to people in the 80s/90s when they could actually type
Meta-Ctrl-C on their keyboard to input them.

Noaways, you can still enter ^C with Ctrl+C but bytes >= 0x80
are used for non-ASCII characters, and Alt-C usually sends ^[c
(0x1b 0x63) and Alt-Ctrl-C ^[^C (0x1b 0x3)

I find the \x83 representation more useful when giving visual
representations of bytes not forming part of a printable
characters (and \uffff / \U0010ffff for valid but non-printable
multi-byte characters). Octal used to be more popular than hex,
but I think nowadays it's the reverse, though I still find \203
more useful than \M-^C if not \x83.

What do people think?

Would it make sense to change some of the output intended for
user consumption such as:

$ a=$'\x83'
$ typeset a
a=$'\M-\C-C'
$ print -r ${(q+)a}
$'\M-\C-C'
$ (set -x; : $a)
+/bin/zsh:29> : $'\M-\C-C'


$ let $a
zsh: bad math _expression_: illegal character: \M-C
$ let 1+$a
zsh: bad math _expression_: operand expected at `\M-^C'

(another M-C vs M-^C bug above by the way).

Comparison with some other tools/shells:

$ echo $a | cat -v
M-^C
$ echo $a | sed -n l
\203$
$ bash -xc 'printf "%q\n" "$a"'
+ printf '%q\n' $'\203'
$'\203'
$ ksh -xc 'printf "%q\n" "$a"'
+ printf '%q\n' $'\x83'
$'\x83'

--
Stephane



--
Mark J. Reed <markjreed@xxxxxxxxx>


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