Re: Bash bug?



On Thu, Mar 30, 2006 at 07:39:34PM -0500, T wrote:
On Wed, 29 Mar 2006 20:18:07 -0600, Sumo Wrestler (or just ate too much)
wrote:

the command printf seems to be ignoring the ending '\n' that passes to
it:

[...]

It's an interaction between the echo command and the shell that's causing
the trailing \n to be removed. Printf is working just fine: $ printf
"hello\n" | od -t x1 -
0000000 68 65 6c 6c 6f 0a
0000006
This is the correct output. But what happens when you use echo: $ echo
-n `printf "hello\n\n\n\n\n"` | od -t x1 - 0000000 68 65 6c 6c 6f
0000005

oh, thanks for the input. It really made me thinking, and I found that it
is not echo's fault, because the previous \n was printed ok. here is more
test:

$ echo -n "`printf "hello\n\n"`" | od -t x1 -
0000000 68 65 6c 6c 6f
0000005

but:

$ echo -n "`printf "hello\n\n "`" | od -t x1 -
0000000 68 65 6c 6c 6f 0a 0a 20
0000010

So is it bash that is eating the trailing \n's?

Perhaps I'm missing something... but you're still using echo.

According to echo(1):

-n do not output the trailing newline

In the first example you indeed have trailing newlines, while in the
second there's a trailing space and so no trailing newline. This looks
consistent to me.

--
Ken Irving, fnkci@xxxxxxx


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: Bash bug?
    ... It's an interaction between the echo command and the shell that's causing ... Printf is working just fine: ... So is it bash that is eating the trailing \n's? ...
    (Debian-User)
  • Re: Newbee question about printf
    ... Consider getting rid of the trailing ";". ... printf; ... Another "problem" I have is that I would like to supress the print out ... 'regex' in my input file. ...
    (comp.lang.awk)
  • Re: Again: Please hear my plea: print without softspace
    ... > now prints foo with a trailing newline. ... > suppresses the trailing newline but adds a trailing space. ...
    (comp.lang.python)
  • Re: unix network programing help!
    ... > trailing '\0' of the string, but you don't want to send that. ... > you must append it manually before passing the buffer to printf(). ...
    (comp.os.linux.development.apps)