bug-bash
[Top][All Lists]
Advanced

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

Re: no trailing newline causes read to fail


From: Stephane Chazelas
Subject: Re: no trailing newline causes read to fail
Date: Fri, 1 Oct 2004 09:08:41 +0100
User-agent: Mutt/1.5.6i

On Thu, Sep 30, 2004 at 10:48:48PM -0700, Stephen Samuel wrote:
[...]
> Repeat-By:
>               `echo -n 'this is a test' > /tmp/f ;read line</tmp/f ` || 
>               echo failed $line
>       results in the output:
>               failed this is a test
> 
>               echo -e -n 'two lines \n of output' > /tmp/f
>                while read line ; do echo $line; done  ; echo $line
>       results in the output:
>               two lines
> 
>       At the end of the loop '$line' is empty (i.e. the last line is lost).
> 
> I cam gemerate some sympathy for wanting to return some sort of error on a 
> partial
> line of input, but I really don't like silently losing data.
> 
> I think that the correct way of responding is that either the read should 
> succeed,
> or the variable 'line' should contain data after the while loop terminates.
[...]

A line must end in a <NL> character, otherwise it's not a text
line. bash behavior is POSIX conformant.

http://www.opengroup.org/onlinepubs/009695399/utilities/read.html

    EXIT STATUS

     The following exit values shall be returned:

      0
             Successful completion.
     >0
             End-of-file was detected or an error occurred.

http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html

   3.205 Line

   A sequence of zero or more non- <newline>s plus a terminating
   <newline>.


ksh, dash and zsh behave the same

-- 
Stephane

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________




reply via email to

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