Bug 12566 - ash: read with -t 0 does not return failure if nothing is read after a successful first read
Summary: ash: read with -t 0 does not return failure if nothing is read after a succes...
Status: RESOLVED INVALID
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.31.x
Hardware: All Linux
: P5 trivial
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-19 17:58 UTC by Geoff Winkless
Modified: 2020-02-19 18:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geoff Winkless 2020-02-19 17:58:10 UTC
echo "a" | if read -t 0 a ; then echo $a; a=cleared; if read -t 0 a; then echo $a; fi; fi

outputs

blah
cleared

I'm a little confused by this. Would expect the second read to return failure, but it does not. Indeed, any subsequent reads on the same pipe return true.

Can work around by using -t 0.001 but it seems a little odd.
Comment 1 Geoff Winkless 2020-02-19 18:02:25 UTC
And immediately after I hit "send" I realised that the first read is also not populating $a either - my initial tests were with "blah", I hadn't realised that it hadn't changed to "a" as expected.

So read -t 0 a simply doesn't populate a at all, but returns true.
Comment 2 Geoff Winkless 2020-02-19 18:16:52 UTC
This actually matches other shells' behaviour, even though unexpected on my part. Apologies for timewasting.