I tried to use "read -t 0" to check if there is any data on the STDIN or not.

The man page said:

If timeout is 0, read returns success if input is available on the specified 
file descriptor, failure otherwise.

Maybe I made a mistake but I tested and I got variable results:

arpad@terminus ~ $ for(( i=0; i<10; i++ )); do echo -n "a" | read -t 0 ; echo 
$?; done | sort | uniq -c
     10 0
arpad@terminus ~ $ for(( i=0; i<10; i++ )); do echo -n "a" | read -t 0 ; echo 
$?; done | sort | uniq -c
      8 0
      2 1
arpad@terminus ~ $ for(( i=0; i<10; i++ )); do echo -n "a" | read -t 0 ; echo 
$?; done | sort | uniq -c
     10 0

I tried this on 2 machines with the same results:

GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
GNU bash, 4.2.45(1)-release (x86_64-pc-linux-gnu) verzió


Am I doing something wrong? Did I misunderstand the documentation? Or is there 
a race condition?

Thanks,

Arpad Kunszt

Reply via email to