bug-bash
[Top][All Lists]
Advanced

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

no trailing newline causes read to fail


From: Stephen Samuel
Subject: no trailing newline causes read to fail
Date: Thu, 30 Sep 2004 22:48:48 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a3) Gecko/20040817

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: i386-redhat-linux-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib 
-D_FILE_OFFSET_BITS=64 -O2 -g -pipe -march=i386 -mcpu=i686
uname output: Linux me.bcgreen.com 2.6.8-1.521 #1 Mon Aug 16 09:01:18 EDT 2004 
i686 i686 i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:

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.

(sh does the later for OpenBSD-3.3 and FreeBSD4.7 but not FreeBSD-3.2)




reply via email to

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