[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Builtin read with -n0 or -N0 (nchars == 0) behaves as a read with no
From: |
dualbus |
Subject: |
Re: Builtin read with -n0 or -N0 (nchars == 0) behaves as a read with no -n/-N argument |
Date: |
Sun, 4 Jun 2017 00:16:09 -0500 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Sun, Jun 04, 2017 at 01:45:42AM +0530, Pranav Deshpande wrote:
[...]
> My solution is to change *line 294* of builtins/read.def.
>
> Change
> if (code == 0 || *intval < 0* || intval != (int)intval)
>
> to
>
> if (code == 0 || i*ntval <= 0* || intval != (int)intval)
[...]
> Is this solution ok?
Yes. That works.
Chet went with the other option though:
dualbus@debian:~/src/gnu/bash-build$ ./bash -c 'read -n0; echo $?; declare -p
REPLY'
0
declare -- REPLY=""
You can see the change by navigating the `devel' branch of the git repository
in Savannah (commit 1110e30870a8782425067a060d89cc411b014418):
http://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=1110e30870a8782425067a060d89cc411b014418
Although there's a problem with the solution:
dualbus@debian:~$ for sh in bash ~/src/gnu/bash-build/bash ksh93 mksh; do $sh
-c ': | read -n 0; echo $?'; done
1
0
1
1
Since the read(2) system call doesn't take place, `read -n 0' doesn't detect
the broken pipe. IMO, it should.
--
Eduardo Bustamante
https://dualbus.me/