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)
- X-seq: zsh-users 26920
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: "Zach Riggle" <zachriggle@xxxxxxxxx>
- Cc: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>, zsh-users@xxxxxxx
- Subject: Re: Odd behavior with various (q) array modifiers and non-printable characters (backspace, newline)
- Date: Wed, 11 Aug 2021 17:42:09 -0400
- Archived-at: <https://zsh.org/users/26920>
- In-reply-to: <CAH+w=7bkaBZYR0Ok+zwqEqNDAjRDK1GyP9k74wY4-X+6jOrTEw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5k=MRwfuR_xNzJjUAMO8ds7Kr=OpM2QMD9+A9hLKHu3iw@mail.gmail.com> <CAH+w=7bkaBZYR0Ok+zwqEqNDAjRDK1GyP9k74wY4-X+6jOrTEw@mail.gmail.com>
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.
Presumably you thought "..." works like $'...'.
% mysed_orig=( gsed "s/\ba\b/x/" )
% typeset -p mysed_orig
typeset -a mysed_orig=( gsed 's/\ba\b/x/' )
% mysed_fixed=(gsed $'s/\ba\b/x/')
% typeset -p mysed_fixed
typeset -a mysed_fixed=( gsed $'s/\C-Ha\C-H/x/' )
% newline_orig=( aa "b\nb" cc )
% typeset -p newline_orig
typeset -a newline_orig=( aa 'b\nb' cc )
% newline_fixed=( aa $'b\nb' cc )
% typeset -p newline_fixed
typeset -a newline_fixed=( aa $'b\nb' cc )
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 `!').
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author