help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about read


From: alex xmb ratchev
Subject: Re: question about read
Date: Thu, 27 Jul 2023 08:08:03 +0200

On Wed, Jul 26, 2023, 11:54 PM Greg Wooledge <greg@wooledge.org> wrote:

> On Wed, Jul 26, 2023 at 10:22:08PM +0200, alex xmb ratchev wrote:
> > there is problem on noneol end ? or the like ?
> > i remember many discussion and my testing was it completly misses .. .. ?
>
> If you read a line that doesn't end with a newline, read will return a
> non-zero exit status, but will leave the content in the variable(s).
>
> So, code that looks like this:
>
>     while read -r line; do
>         ...
>     done < somefile
>
> will "fail" to process the last line of the file, if that line is
> incomplete (no newline).  This can be surprising.  The easiest workaround
> (besides fixing your broken input file) is:
>
>     while read -r line || [[ $line ]]; do
>         ...
>     done < somefile
>
> That forces the loop body to be executed on the final partial line,
> if there is one.
>
> Did you have a different question, or is this what you were thinking of?
>

thats exactly what i wanted , thank you big time

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]