[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
read -t 0 anomaly
From: |
Kunszt Árpád |
Subject: |
read -t 0 anomaly |
Date: |
Fri, 04 Oct 2013 13:20:16 +0200 |
User-agent: |
KMail/4.10.5 (Linux/3.10.7-gentoo-syrius; KDE/4.10.5; x86_64; ; ) |
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
- read -t 0 anomaly,
Kunszt Árpád <=