[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Builtin read with -n0 or -N0 (nchars == 0) behaves as a read with no -n/
Builtin read with -n0 or -N0 (nchars == 0) behaves as a read with no -n/-N argument
Tue, 23 May 2017 10:33:17 -0500
(I think this is a good problem for Pranav to tackle if you consider
this to be a bug, Chet).
address@hidden:~$ bash -c 'read -n0 <<< "abc"; declare -p REPLY'
declare -- REPLY="abc"
address@hidden:~$ bash --version|head -n1
GNU bash, version 4.4.11(1)-release (x86_64-pc-linux-gnu)
#1 nchars <= 0 treated as an error
address@hidden:~/src/gnu/bash-build$ ./bash -c 'read -n0 <<< "abc";
declare -p REPLY'
./bash: line 0: read: 0: invalid number
./bash: line 0: declare: REPLY: not found
#2 adopt the same semantics as POSIX read(2) syscall
| Before any action described below is taken, and if nbyte is zero, the read()
| function may detect and return errors as described below. In the absence of
| errors, or if error detection is not performed, the read() function shall
| return zero and have no other results.
This is what the rest of the shells that support a similar option do:
address@hidden:~$ for sh in bash ksh93 mksh zsh; do echo $sh $($sh -c
'set -- -n 0; [ -n "$ZSH_VERSION" ] && set -k 0; read "$@" REPLY <<<
abc; typeset -p REPLY'); done
bash declare -- REPLY="abc"
mksh typeset REPLY=
zsh typeset REPLY=''
I'm in favour of #2.
This was reported by Freenode user `mknod' in #bash
- Builtin read with -n0 or -N0 (nchars == 0) behaves as a read with no -n/-N argument,
Eduardo Bustamante <=