GNU bug report logs -
#20954
wc - linux
Previous Next
Reported by: tele <swojskichlopak <at> wp.pl>
Date: Thu, 2 Jul 2015 00:46:03 UTC
Severity: normal
Tags: notabug
Done: Bob Proulx <bob <at> proulx.com>
Bug is archived. No further changes may be made.
Full log
Message #18 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
So,
$ 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 :-)
[Message part 2 (text/html, inline)]
This bug report was last modified 9 years and 327 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.