* read -r flag not working on 5.8.1
@ 2021-08-08 5:38 David Milum
2021-08-08 5:53 ` David Milum
0 siblings, 1 reply; 4+ messages in thread
From: David Milum @ 2021-08-08 5:38 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 446 bytes --]
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)
According to pacman the installed version is 5.8.1
I was also able to reproduce on my mac
zsh 5.7.1 (x86_64-apple-darwin19.0)
[-- Attachment #2: Type: text/html, Size: 616 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: read -r flag not working on 5.8.1
2021-08-08 5:38 read -r flag not working on 5.8.1 David Milum
@ 2021-08-08 5:53 ` David Milum
2021-08-08 5:59 ` Mikael Magnusson
0 siblings, 1 reply; 4+ messages in thread
From: David Milum @ 2021-08-08 5:53 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 699 bytes --]
Disregard, and apologies for the noise. I understand now -r is not the same
as in bash. Should have clued me in when it didn't work on my mac.
On Sun, Aug 8, 2021 at 1:38 AM David Milum <david.milum.89@gmail.com> wrote:
> 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)
>
> According to pacman the installed version is 5.8.1
>
> I was also able to reproduce on my mac
> zsh 5.7.1 (x86_64-apple-darwin19.0)
>
[-- Attachment #2: Type: text/html, Size: 1126 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: read -r flag not working on 5.8.1
2021-08-08 5:53 ` David Milum
@ 2021-08-08 5:59 ` Mikael Magnusson
2021-08-08 14:04 ` Stephane Chazelas
0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2021-08-08 5:59 UTC (permalink / raw)
To: David Milum; +Cc: zsh-workers
On 8/8/21, David Milum <david.milum.89@gmail.com> wrote:
> Disregard, and apologies for the noise. I understand now -r is not the same
> as in bash. Should have clued me in when it didn't work on my mac.
>
> On Sun, Aug 8, 2021 at 1:38 AM David Milum <david.milum.89@gmail.com>
> wrote:
>
>> 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.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: read -r flag not working on 5.8.1
2021-08-08 5:59 ` Mikael Magnusson
@ 2021-08-08 14:04 ` Stephane Chazelas
0 siblings, 0 replies; 4+ messages in thread
From: Stephane Chazelas @ 2021-08-08 14:04 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: David Milum, zsh-workers
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-08 14:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-08 5:38 read -r flag not working on 5.8.1 David Milum
2021-08-08 5:53 ` David Milum
2021-08-08 5:59 ` Mikael Magnusson
2021-08-08 14:04 ` Stephane Chazelas
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).