Afficher un message
Vieux 18/08/2006, 16h57   #3
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: "read line" ignoring last line

On Fri, 18 Aug 2006 11:21:25 -0400, Bill Marcum wrote:
[...]
>> cat ./data/BACSTEL_APPLICATION_DATA.txt | while IFS= read line
>> do
>> echo $line
>> done
>> ************************************************** ***

>
> Perhaps the file does not end with a newline. A workaround would be
> { cat ./data/BACSTEL_APPLICATION_DATA.txt; echo; } | while IFS= read line

[...]

I don't think any shell implementation would discard such a
line. I don't know of any that does.

POSIX doesn't seem very clear on that matter. It doesn't seem to
cover the case where eof is reached while reading a line. Reading
http://www.opengroup.org/onlinepubs/...ties/read.html,
one could tell that not a single shell is conformant.

Apparently, if $IFS doesn't contain the newline character, then
in

read var

$var should contain the entire line read, that is including the
trailing newline character. All the shells I know strip the line
terminator, which makes sense.

--
Stephane
  Réponse avec citation
 
Page generated in 0,04365 seconds with 9 queries