bug-bash
[Top][All Lists]
Advanced

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

Re: EOF does not work in echo


From: Cai Qian
Subject: Re: EOF does not work in echo
Date: Fri, 26 May 2006 02:04:59 +0100

Hi,

On 5/26/06, Chris F.A. Johnson <address@hidden> wrote:
On 2006-05-25, Cai Qian wrote:
> Hi,
>
> echo -e "hello \004world" | cat
>
> will print out
>
> hello world

    As it should.

> echo -e "hello \004world" | cat > /dev/null
>
> will print out nothing

    Of course: you sent it all to /dev/null.

> It suggests that "cat" has not seen EOF (004) generated by echo.

    Try piping it to od or hexdump:

$ echo -e "hello \000world" | hexdump -C
00000000  68 65 6c 6c 6f 20 00 77  6f 72 6c 64 0a           |hello .world.|
0000000d

    Do you expect cat to stop printing after \004? It won't; it will
    print all characters. If it didn't, it would be of no use for
    concatenating binary files.


It seems nobody will stop reading when see EOF.

 echo -e "hello \004world" | { read i; echo i = $i; }

It would be nice if we can manually generate a EOF to terminate a
program's reading from STDIN. Therefore, we can do something like,

unset i; unset j; echo -e "hello \004world" | { read i; echo i = $i;
read j; echo j = $j;}

i = hello
j = world

Qian




reply via email to

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