From: Stephane Chazelas <stephane@chazelas.org>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: David Milum <david.milum.89@gmail.com>, zsh-workers@zsh.org
Subject: Re: read -r flag not working on 5.8.1
Date: Sun, 8 Aug 2021 15:04:42 +0100 [thread overview]
Message-ID: <20210808140442.bm2g3qmjtxmr5ybb@chazelas.org> (raw)
In-Reply-To: <CAHYJk3RGQh==kYGy4SN4LrrN7t6hDO3Ayc4YF1-7RNZLCKkZtA@mail.gmail.com>
2021-08-08 07:59:20 +0200, Mikael Magnusson:
[...]
> >> Hello, seems like the -r (raw mode) flag which should prevent it from
> >> interpreting backslashes is not working? My understanding is the
> >> following
> >> example shouldn't clear the "CLEAR" part. I can also demonstrate with new
> >> lines.
> >>
> >> $ read -r TEST
> >> asd\c CLEAR
> >> $ echo $TEST
> >> asd
> >> $ zsh --version
> >> zsh 5.8 (x86_64-pc-linux-gnu)
>
> Your problem is not read, but echo. Try the above with echo -E $TEST
> instead and you will see the read command is fine.
[...]
More precisely, to print the contents of a scalar variable
verbatim followed by a newline character in zsh:
echo -E - $var # zsh only
print -r - $var # zsh
print -r -- $var # zsh
print -r - "$var" # zsh/ksh
printf '%s\n' "$var" # POSIX
echo -En "$var"$'\n' # zsh/bash and a few other echo
# implementations (but for bash, not if
# both the xpg_echo and posix options are
# enabled).
cat << EOF # Bourne/POSIX
$var
EOF
cat <<< "$var" # zsh and a few other shells
See also
zmodload zsh/system
syswrite -- "$var"$'\n' ||
syserror -p failed: $ERRNO
for a raw interface to the write() system call.
And btw, to read a line into a variable, the syntax is
IFS= read -r var
(in zsh or any other POSIX shell, though only zsh can read lines
containing NUL bytes).
See
https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
https://unix.stackexchange.com/questions/209123/understanding-ifs-read-r-line
--
Stephane
prev parent reply other threads:[~2021-08-08 14:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-08 5:38 David Milum
2021-08-08 5:53 ` David Milum
2021-08-08 5:59 ` Mikael Magnusson
2021-08-08 14:04 ` Stephane Chazelas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210808140442.bm2g3qmjtxmr5ybb@chazelas.org \
--to=stephane@chazelas.org \
--cc=david.milum.89@gmail.com \
--cc=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).