Bug 12566

Summary: ash: read with -t 0 does not return failure if nothing is read after a successful first read
Product: Busybox Reporter: Geoff Winkless <busybox>
Component: OtherAssignee: unassigned
Status: RESOLVED INVALID    
Severity: trivial CC: busybox-cvs
Priority: P5    
Version: 1.31.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

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.