Wendy Lin
2015-01-21 19:15:29 UTC
How can I detect if I reached EOF or HUP on a pipe or socket?
bash gives 142 as return code for the read builtin:
$ bash -c 'printf "abc" | while read -N 1 c ; res=$? ; echo $res ; ((
res == 0 )) ; do true ; done ; read -n 1 -t 1 c ; res=$? ; echo $res'
0
0
0
1
142
ksh however gives 1 as return code for the read builtin, which is not
different from the condition when we wait for more data:
ksh -c 'printf "abc" | while read -N 1 c ; res=$? ; echo $res ; (( res
== 0 )) ; do true ; done ; read -n 1 -t 1 c ; res=$? ; echo $res'
0
0
0
1
1
Wendy
bash gives 142 as return code for the read builtin:
$ bash -c 'printf "abc" | while read -N 1 c ; res=$? ; echo $res ; ((
res == 0 )) ; do true ; done ; read -n 1 -t 1 c ; res=$? ; echo $res'
0
0
0
1
142
ksh however gives 1 as return code for the read builtin, which is not
different from the condition when we wait for more data:
ksh -c 'printf "abc" | while read -N 1 c ; res=$? ; echo $res ; (( res
== 0 )) ; do true ; done ; read -n 1 -t 1 c ; res=$? ; echo $res'
0
0
0
1
1
Wendy