Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15753 > unrolled thread

read -t 0 fails to detect input.

Started byBize Ma <binaryzebra@gmail.com>
First post2019-12-18 19:40 -0400
Last post2019-12-18 19:40 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  read -t 0 fails to detect input. Bize Ma <binaryzebra@gmail.com> - 2019-12-18 19:40 -0400

#15753 — read -t 0 fails to detect input.

FromBize Ma <binaryzebra@gmail.com>
Date2019-12-18 19:40 -0400
Subjectread -t 0 fails to detect input.
Message-ID<mailman.1114.1576712471.1979.bug-bash@gnu.org>
It seems that read -t 0 should detect if there is input from a pipe (and
others).

>From man bash:

>> If  timeout is 0, read returns immediately, without trying to read any
data.
>> The exit status is 0 if input is available on the specified file
 descriptor, non-zero otherwise.

So, it seems that this should print 1:

$ true | read -t 0 var; echo $?
1

And this should print 0 (input available), but it doesn't (most of the
time).

$ echo value | read -t 0 var ; echo $?
1

A little delay seems to get it working:

$ echo value | { read -t 0 var; } ; echo $?
0

Related: Comment to what is wrong with read -t 0:
https://unix.stackexchange.com/questions/33049/how-to-check-if-a-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt/498065?noredirect=1#comment916652_497121

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-2bxm7h/bash-5.0=.
-fstack-protector-strong -Wformat -We$
uname output: Linux iodeb 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2
(2019-11-11) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 3
Release Status: release

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web