Re: while loops can not read "\"

2020-12-23 Thread Chet Ramey

On 12/23/20 10:34 AM, Ilkka Virta wrote:
Regardless, my point is that "as with word splitting" is not exactly true, 
and misleading statements
have no place in documentation if it's meant to be of any use to a user who 
needs the documentation

to begin with.


I'll look at doing something for the next version, when there will be
another round of translations.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: while loops can not read "\"

2020-12-23 Thread Ilkka Virta
Regardless, my point is that "as with word splitting" is not exactly true,
and misleading statements
have no place in documentation if it's meant to be of any use to a user who
needs the documentation
to begin with.

In any case, adding "A backslash can be used to escape a delimiter or a
newline." shouldn't make
the text significantly heavier, given it already uses almost double the
letters to spell out how the words
are assigned to the names given in order.


On Wed, Dec 23, 2020 at 4:44 PM Chet Ramey  wrote:

> On 12/22/20 9:13 AM, Ilkka Virta wrote:
> > Arguably it's a bug that 'help read' doesn't mention the effect of
> > backslashes, other than what can be extrapolated from the description of
> > -r. It only says "The line is split into fields _as with word
> splitting_",
> > but word splitting doesn't recognize backslashes as special. It should
> not
> > be necessary to read the description of all options to infer the
> behaviour
> > of a command as used without them.
>
> That isn't the function of `help'. The help documentation is intended to be
> a quick reference, not to duplicate everything in the man page.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
>


Re: while loops can not read "\"

2020-12-23 Thread Chet Ramey

On 12/22/20 9:13 AM, Ilkka Virta wrote:

Arguably it's a bug that 'help read' doesn't mention the effect of
backslashes, other than what can be extrapolated from the description of
-r. It only says "The line is split into fields _as with word splitting_",
but word splitting doesn't recognize backslashes as special. It should not
be necessary to read the description of all options to infer the behaviour
of a command as used without them.


That isn't the function of `help'. The help documentation is intended to be
a quick reference, not to duplicate everything in the man page.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: while loops can not read "\"

2020-12-22 Thread Ilkka Virta
Arguably it's a bug that 'help read' doesn't mention the effect of
backslashes, other than what can be extrapolated from the description of
-r. It only says "The line is split into fields _as with word splitting_",
but word splitting doesn't recognize backslashes as special. It should not
be necessary to read the description of all options to infer the behaviour
of a command as used without them.

The online reference is clearer on this:
https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-read

On Tue, Dec 22, 2020 at 4:05 PM  wrote:

> On 22/12/2020 08:18, ffvh gfff wrote:
> > Machine: x86_64
> > OS: linux-gnu
> > Compiler: gcc
> > Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat
> > -Werror=format-security -Wall
> > uname output: Linux kali 5.7.0-kali1-amd64 #1 SMP Debian 5.7.6-1kali2
> > (2020-07-01) x86_64 GNU/Linux
> > Machine Type: x86_64-pc-linux-gnu
> >
> > Bash Version: 5.1
> > Patch Level: 0
> > Release Status: release
> >
> > command line:
> > cat poc.txt | while read i; do echo $i;do
> In fact, the read builtin can read backslashes. It's just that you
> didn't escape them. Use the -r option.
>
> $ help read | grep -- -r
>-r   do not allow backslashes to escape any characters
>
> $ echo '\' | { read i; echo "$i"; }
>
> $ echo '\' | { read -r i; echo "$i"; }
> \
>
> --
> Kerin Millar
>
>


Re: while loops can not read "\"

2020-12-22 Thread Greg Wooledge
On Tue, Dec 22, 2020 at 04:18:39PM +0800, ffvh gfff wrote:
> command line:
> cat poc.txt | while read i; do echo $i;done
> it can not read "\"

You forgot to use the -r option in your read command.



Re: while loops can not read "\"

2020-12-22 Thread

On 22/12/2020 08:18, ffvh gfff wrote:

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux kali 5.7.0-kali1-amd64 #1 SMP Debian 5.7.6-1kali2
(2020-07-01) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 0
Release Status: release

command line:
cat poc.txt | while read i; do echo $i;do
In fact, the read builtin can read backslashes. It's just that you 
didn't escape them. Use the -r option.


$ help read | grep -- -r
  -rdo not allow backslashes to escape any characters

$ echo '\' | { read i; echo "$i"; }

$ echo '\' | { read -r i; echo "$i"; }
\

--
Kerin Millar



while loops can not read "\"

2020-12-22 Thread ffvh gfff
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux kali 5.7.0-kali1-amd64 #1 SMP Debian 5.7.6-1kali2
(2020-07-01) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 0
Release Status: release

command line:
cat poc.txt | while read i; do echo $i;done
it can not read "\"
but for loops can read:
for i in $(cat ~/poc.txt);do echo $i;done
\
\
\
\
\
hello
world