14:13:58 hi, unix question if you don't mind. when using fread, it's possible to detect error from EOF using the feof and/or ferror interfaces, however, can such read error be detected in a shell script reading from stdin? can stdin have read error at all? if yes, as far as i know "read" does not distinguish read error from EOF, but data=$(cat) (with the caveats of LF truncation and finite stream) might error on read, right? 14:17:02 the goal is to be absolutely sure that as far as the script can tell, the whole input has reached the shell script successfully. 15:35:12 avih: If there a short read of the file then cat would return an error and exit non-zero. 16:26:39 w 16:30:16 bahamat: thanks. i think the first question is whether at all stdin can have read error which is distinguishable from EOF. first in a C program, and then in a shell script. and if the answer is yes for a shell script, then continue to ways of detecting this case 17:30:40 avih: Well fread() and a shell script using cat are different things. A userland process using fread is supposed to use ferror/feof. If it doesn't, that's probably a bug in that program. If you're writing a shell script you don't need to worry about what functions or system calls are being used. However the command behaves is the interface you need to deal with. 18:21:02 ok, let's forget the shell script. if a c program uses fread on stdin, is there ever a use case where ferror returns true? 18:21:21 if yes, how to synthesize it? 18:23:27 i.e. how to invoke/set-it-up so that ferror(stdin) ends up true? 18:27:31 it's easy to synthesize a use case where fwrite ends in ferror, e.g. if the receiving side of pipe closes, then the writing side gets a write error. but how is it possible to get a read error? in a pipe, if the writing side closes, then i don't think the reading side gets an error. it only sees feof, not ferror