Problem with read in sh

I've discovered a very annoying problem in sh:

echo -en "one\ntwo\nthree" | while read VALUE
do
        echo "${VALUE}"
done

This will print one and two, but not three. The last line is IGNORED because it lacks a newline. This makes it hard to use sh for things like CGI scripting; you have to add a newline with sed or something. How can I coerce read into reading the last line?

For me it's printing..perfectly.
one
two
three

Works in ksh an sh on my box as well.

Do you have IFS set to something wierd?

I haven't changed the value of IFS. What version of echo do you have? The version I use implements the '-n' flag, which prevents it from printing the final newline, like so:

 # echo -n "Hello"
hello# 

If yours does not have -n, the example won't fail.

I am using GNU bash 3.1.16.

Just confirming that this is the behaviour under GNU bash for me also.

I have a question, I'm sure there is a reason you want to do it this way, but why use the -n if piping to another command in the way you describe?

It's just an example. The real problem is getting bash to read POST input from the CGI interface, which is fed into stdin and also has no trailing newline. Right now I have to do crazy manipulations with sed and exec. With enough work I can probably find less crazy ways, but all of them involve launching a new process instead of using a builtin, which annoys me to no end.

I've discovered part of the reason.

#!/bin/sh

while read LINE
do
        echo "${LINE}"
done

echo "${LINE}"
# echo -en "hello\nworld" | ./readtest.sh
hello
world
#

GNU bash returns error on EOF, even when there was some data. I'll just have to test for empty strings.