|
| From: | tele |
| Subject: | bug#20954: wc - linux |
| Date: | Thu, 2 Jul 2015 12:19:59 +0200 |
| User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 |
tag 20954 + notabug close 20954 thanks tele wrote: Hi! Hi! From terminal: $ a="" ; echo $s | wc -l 1 Do you mean $a instead of $s? Either way is the same though assuming $s is empty too. - Yes, my mistake :-) Should be 0 , yes ? No. Should be 1. You have forgotten about the newline at the end of
the command. The echo will terminate with a newline. You can see
this with od.
echo | od -tx1 -c
0000000 0a
\n
Since this appears to be a usage error I have closed the bug. Please
feel free to follow up with more information. We will read it. And
we appreciate additional communication! I am simply closing it to
keep the accounting straight.
Bob
# "echo" gives in new line, "echo -n" subtracts 1 line, but "wc -l" can count only from new line,
# so if something exist inside first line "wc -l" can not count. :-(
# example:
#
# $ a="j" ; echo "$a" | wc -l
# 1
#
# $ a="" ; echo "$a" | wc -l
# 1
#
# $ a="" ; echo -n "$a" | wc -l
# 0
#
# $ a="j" ; echo -n "$a" | wc -l
# 0
$ a="" ; echo "$a" | sed '/^\s*$/d' | wc -l 0 $ a="3" ; echo "$a" | sed '/^\s*$/d' | wc -l 1 Can be added option to "wc" to fix this problem without use sed in future ? Thanks for helping :-) |
| [Prev in Thread] | Current Thread | [Next in Thread] |