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

read -r and bad surprises (Was: indirect assignment to array)



2020-04-16 20:04:57 +0200, Pier Paolo Grassi:
[...]
> thanks but I really hate when I find out bugs that i never have thought of
> (a big one has been discovering the -r flag to read)
[...]

While you're there, note that the syntax to read a line of input
verbatim is:

IFS= read -r line

not just read -r line.

Compare:

$ print -r ' a\b ' | IFS= read -r a; printf '<%s>\n' $a
< a\b >
$ print -r ' a\b ' | read -r a; printf '<%s>\n' $a
<a\b>
$ print -r ' a\b ' | read a; printf '<%s>\n' $a
<ab>

See https://unix.stackexchange.com/questions/209123/understanding-ifs-read-r-line
for details.

-- 
Stephane



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