bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read -t 0 fails to detect input.


From: Bize Ma
Subject: read -t 0 fails to detect input.
Date: Wed, 18 Dec 2019 19:40:45 -0400

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]