Newsgroups: gmane.linux.debian.user Date: Wed, 29 Mar 2006 18:59:32 -0500
Newsgroups: gmane.linux.debian.user Date: Wed, 29 Mar 2006 18:59:32 -0500
the command printf seems to be ignoring the ending '\n' that passes to it:
$ test=`/usr/bin/printf "1\n a\n "`
$ echo "$test<end>" 1 a <end>
$ test=`/usr/bin/printf "1\n a\n"`
$ echo "$test<end>" 1 a<end>
The only different between 2nd and 1st assignment of test is the ending space.
I need the ending "\n" to place "<end>" at next line after "a", without the leading space. How can I do that?
T
PS, my printf:
$ /usr/bin/printf --version printf (GNU coreutils) 5.2.1
>> 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
T
ps, my bash
$ bash --version GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
> So is it bash that is eating the trailing \n's?
Yes, but it's not a bug. See the section about “Command Substitution” in the bash(1) man page.
Matthew R. Dempsky
> Yes, but it's not a bug. See the section about ``Command Substitution'' > in the bash(1) man page.
Got it:
,----- | Bash performs the expansion by executing command and replacing the | command substitution with the standard output of the command, with any | trailing newlines deleted. Embedded newlines are not deleted. `-----
the "feature" is so confusing.
T
> the "feature" is so confusing.
It's so that shell snippets like
cd /lib/modules/`uname -r`/build
work correctly without extra hassle.
Matthew R. Dempsky