Re: "read line" ignoring last line
William wrote:
> "Anoop" <anoopkumarv@gmail.com> wrote in message
> news:1155912577.327410.285380@75g2000cwc.googlegro ups.com...
> > Hi All,
> >
> > I am facing a wierd problem. I have about a 100 shell scripts all coded
> > in a similar fashion. All of them read from some file(s) and process
> > the data.
> >
> > But there is this one script which reads from a small file which has
> > only 2 lines of data. What happens (and happens only for this script)
> > is that only the first line is read, and the last line is ignored
> > completely. I do not get any errors.
>
> As Bill Marcum suggested, the problem is in the file, not the
> script. I can reproduce your problem by creating a file whose
> last line does not have a newline character at the end (read
> is looking for this character, cat doesn't care). A newline
> tells read it has a full line in the buffer and it's time to
> copy it to your variable, but it's hitting the end of the file
> before that happens, so...
>
> -Wm
I agree - but these files were handcoded and come from the client side
- we cannot control what comes from them..
But the workaround posted by Bill Marcum works fine. I think I am going
ahead with modifying just that one script...
Thanks alot to all,
Anoop
|