On 2/25/11, Bob Proulx <[email protected]> wrote: > Personally I have never thought about that possibility nor needed it. > >> So should I be using a head-alike for iterating over lines, and >> would such an utility belong to a GNU package, or is awk the right >> tool for the job? > > What are you trying to do? > Something along the lines of: % cat bin/prompt while head -n1 >/dev/tty do head -n1 </dev/tty done % cat prompt/pkg Some variable Another variable % bin/prompt < prompt/pkg | bin/pkg args | paste pre/pkg /dev/stdin post/pkg > Some variable < some value > Another variable < another value output value unit
where shell commands are prefixed with '% ', output written to /dev/tty with '> ' and input read from /dev/tty with '< '. Output written to stdout and not redirected by the shell is not prefixed. Although the end of prompt/pkg is reached every time a user inputs a line after the first `wc -l<prompt/pkg` lines, a SIGPIPE is never sent as each head process reaches EOF at most once, and exits without notifying the script. It seems natural to notify about EOF with an exit status. Instead, I worked around this by passing the length of stdin in argv, although I could've counted the lines in stdin prior to prompting (or after printing the first prompt). The only way I can imagine scripts braking due to head returning non-zero upon premature EOF are scripts that consider every non-zero exit fatal, but don't know many lines their input is. How many can they be?
