Thanks, David. I didn't think of checking after the while loop terminated. Any chance of adding this to the man page or maybe a FAQ?
perl -e 'print "a b\nc d "' | while read x y ;do echo "<$x><$y>" ;done [[ $x$y = "" ]] || echo "<<$x><$y>>" perl -e 'print "a b\nc d\n"' | while read x y ;do echo "<$x><$y>" ;done [[ $x$y = "" ]] || echo "<<$x><$y>>" produces the following for both ksh88 and ksh93 ($'...' doesn't work in ksh88 Version M-11/16/88f): <a><b> <<c><d>> <a><b> <c><d> > -----Original Message----- > From: David Korn [mailto:[email protected]] > Sent: Wednesday, October 20, 2010 6:43 PM > To: [email protected]; Wiersba, John (Hlthcr&Science) > Subject: Re: [ast-developers] read ignores an input line > missing a trailing newline > > cc: [email protected] > Subject: Re: [ast-developers] read ignores an input line > missing a trailing newline > -------- > > > Living in a mixed unix/linux/windows world, this has bitten > me more than > > once: > > > > $ /usr/bin/perl -e ' print "a b\nc d" ' | while read x y ;do echo > > "<$x><$y>" ;done > > a b > > > > I can't see how it is not a bug to silently discard/ignore > the non-empty > > data after the last newline in a file. > > > > Since this bug appears to have been present in ksh and bash > since the > > time of Moses, so maybe it's too late to change the > behavior. However, > > I haven't found it documented anywhere; could this behavior > at least be > > documented? > > Since read has encountered an EOF, it must return an exit status > 1. > > However, ksh does process the last partial line. > > print -n $'a b\nc d' | while read x y ;do echo "<$x><$y>" ;done > echo "<$x><$y>" > > Will output > a b > c d > > David Korn > [email protected] > > _______________________________________________ ast-developers mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-developers
