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

Re: Odd behavior with various (q) array modifiers and non-printable characters (backspace, newline)

Lawrence Velázquez wrote on Wed, Aug 11, 2021 at 17:42:09 -0400:
> On Wed, Aug 11, 2021, at 5:16 PM, Bart Schaefer wrote:
> > You need to stop testing things with "echo".  The "echo" builtin
> > interprets some backslash escapes itself, which will confuse you about
> > what the quoting options have done.
> > 
> > Repeat all your tests instead with
> >   printf "%s\n" ${(q)...}
> > and so on, and come back if you still have questions.
> Additionally, \b and \n are not interpreted in double quotes, so
> your initial data does not actually contain BS or NL characters.
> As per the QUOTING section of zshmisc(1):
> 	Inside double quotes (""), parameter and command substitution
> 	occur, and `\' quotes the characters `\', ``', `"', `$',
> 	and the first character of $histchars (default `!').

There are third-party plugins that implement syntax highlighting at the
prompt (I happen to co-maintain one such plugin).  Those plugins are
aware of the quoted docs section, so on input such as
    % foo "bar \n \\ \x"
they will correctly highlight only the «\\» as an escape sequence, and
everything else as literals.

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