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


Groups > gnu.bash.bug > #15753

read -t 0 fails to detect input.

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Bize Ma <binaryzebra@gmail.com>
Newsgroups gnu.bash.bug
Subject read -t 0 fails to detect input.
Date Wed, 18 Dec 2019 19:40:45 -0400
Lines 41
Approved bug-bash@gnu.org
Message-ID <mailman.1114.1576712471.1979.bug-bash@gnu.org> (permalink)
References <CAFra36gNku2DTCyivz+caMGnTf7GvGJUTiWicUnBZatcckXGcQ@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1576712471 3174 209.51.188.17 (18 Dec 2019 23:41:11 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=IspuydX8U1AvSrSlKK+tw2yVL0vhDOIXjvCjKlHRVqs=; b=NvgNygqtZ4EFOs+lYmkXZTlX0BLQHZI5F1wplCueg6DvJRJR/iu2JaW+PCH87ZSTaE R1mTL+A8gR7Irar6UDlnGVhPBsxSNSYfOCj9sb9lbxt/B/ythAko16Tedu6iYS2pA0Z0 gKuUSNBZn6h+2VbpodoDyGbdKTSoQLLFK32cSSpchNnSTzD85yLerBUnsbx+yv2iPoBl KbHO4z7J1QgtNYB0C81TpJP1F0zf9UGjXNlorPt1nfueqco8sWwxMkjycO4hcANsibCy u18vkdY5TacgBFVMezF9omxSa0KiI7RPVAk3QiphhuY53aqRTUHUOoFEYlRd40EO+LiX wD6A==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IspuydX8U1AvSrSlKK+tw2yVL0vhDOIXjvCjKlHRVqs=; b=FblbrnqMbwpioTFro62G2G/Y2ymqX4oKMAPjAthMvBJUpsgQlzO4h/ZAIG5bQEJjnN CW0vu6BWynzUe4e44lIILrHLKQHz/X5GvOre9xHszCvSseHhFX+78Y1e4uOwyqUZoTpQ HPc3Uw7pJfwU6RABKMQ1j4dPHi/SvdOVHhSEGi2PgfX/VAe9StmZ1TKTrXISLl51cPGf 1staz/rBqGjpSyR5SS8uUgYABLb1/6xnIMJjVFG5ZFJzTGLHzMxNsvaKXX7aGvhC2uUG lY5+9GPk+lYB9PEwXOseOVZTOTg5BB2Sr/o5GKaCgSE5yA6GEybsYGTb1sXjflFqxGHJ d0dg==
X-Gm-Message-State APjAAAWZYRMaBl6rikNHsm9OtyBIpN2eB2C7VQORA3LW08hplUNlJoQ3 97y2hazo/44OEquVMi/E9miXDkbhfJhXX4bbDvRZ4+je
X-Google-Smtp-Source APXvYqxr/p6CUQo+n9PCTLvh3fmqOEQNSxXy66aD25R4xUqQdpxSd8O5lXh6C1A8j7ECGCsIB9YwcjLpk/QPMkI9c1s=
X-Received by 2002:a9d:7b50:: with SMTP id f16mr5602973oto.18.1576712464624; Wed, 18 Dec 2019 15:41:04 -0800 (PST)
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::336
X-Content-Filtered-By Mailman/MimeDel 2.1.23
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAFra36gNku2DTCyivz+caMGnTf7GvGJUTiWicUnBZatcckXGcQ@mail.gmail.com>
Xref csiph.com gnu.bash.bug:15753

Show key headers only | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web