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

Re: Bash bug?



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?

> Avoid using "echo" when you need trailing whitespace; instead, write the

Actually, I use echo as an example, the assignment variable is then used
in awk. :-) I need to get the result into a variable. 

thanks

tong

ps, my bash

$ bash --version
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)





Reply to: