From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: tele Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 02 Jul 2015 00:46:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 20954@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.143579795825136 (code B ref -1); Thu, 02 Jul 2015 00:46:03 +0000 Received: (at submit) by debbugs.gnu.org; 2 Jul 2015 00:45:58 +0000 Received: from localhost ([127.0.0.1]:36557 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZASdY-0006WJ-Il for submit@debbugs.gnu.org; Wed, 01 Jul 2015 20:45:58 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59668) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAQbV-0002ab-OY for submit@debbugs.gnu.org; Wed, 01 Jul 2015 18:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAQbO-0007De-UG for submit@debbugs.gnu.org; Wed, 01 Jul 2015 18:35:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:52098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAQbO-0007Cy-0u for submit@debbugs.gnu.org; Wed, 01 Jul 2015 18:35:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAQbM-0005gx-Ji for bug-coreutils@gnu.org; Wed, 01 Jul 2015 18:35:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAQbB-00073i-S9 for bug-coreutils@gnu.org; Wed, 01 Jul 2015 18:35:31 -0400 Received: from mx3.wp.pl ([212.77.101.9]:12214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAQbB-000728-72 for bug-coreutils@gnu.org; Wed, 01 Jul 2015 18:35:21 -0400 Received: (wp-smtpd smtp.wp.pl 23947 invoked from network); 2 Jul 2015 00:35:18 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1435790118; bh=FeUka9ilAeLiFIYWgfBmOMVBYeZz4DDRoDgpJSpnzw4=; h=To:From:Subject; b=huIPSwILY4kHydZX8HgHcsQEmjwYwkwfijGMZropiRdImh0DO9UtCanCw4KJnGLOA yu86reN2E3euD8wAe0uEK4iBYflBdKsTxrwoQ4i4oi+QssF35LhIXYdmRqYVylq1CJ IOPxawFPN26AhYcrU7+ULSk7FT8+eZTk78oBA+n8= Received: from dynamic-78-8-125-198.ssp.dialog.net.pl (HELO localhost.localdomain) (swojskichlopak@[78.8.125.198]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-SHA encrypted SMTP for ; 2 Jul 2015 00:35:18 +0200 From: tele Message-ID: <55946B0E.3080000@wp.pl> Date: Thu, 2 Jul 2015 00:34:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-WP-MailID: 98be7ea3856aebfa6520bdd0529c5c89 X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [YcMk] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Mailman-Approved-At: Wed, 01 Jul 2015 20:45:53 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) Hi! From terminal: $ a="" ; echo $s | wc -l 1 Should be 0 , yes ? From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: Bob Proulx Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 02 Jul 2015 01:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: tele Cc: 20954@debbugs.gnu.org Received: via spool by 20954-submit@debbugs.gnu.org id=B20954.14358012651649 (code B ref 20954); Thu, 02 Jul 2015 01:42:02 +0000 Received: (at 20954) by debbugs.gnu.org; 2 Jul 2015 01:41:05 +0000 Received: from localhost ([127.0.0.1]:36591 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZATUu-0000QL-ED for submit@debbugs.gnu.org; Wed, 01 Jul 2015 21:41:04 -0400 Received: from joseki.proulx.com ([216.17.153.58]:37725) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZATUr-0000Pl-L1; Wed, 01 Jul 2015 21:41:03 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 6395C21846; Wed, 1 Jul 2015 19:41:00 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 2EB022DC4D; Wed, 1 Jul 2015 19:41:00 -0600 (MDT) Date: Wed, 1 Jul 2015 19:41:00 -0600 From: Bob Proulx Message-ID: <20150701193543368876542@bob.proulx.com> References: <55946B0E.3080000@wp.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55946B0E.3080000@wp.pl> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.6 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) 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. > 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 From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: Stephane Chazelas Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 02 Jul 2015 13:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: Bob Proulx Cc: 20954@debbugs.gnu.org, tele Received: via spool by 20954-submit@debbugs.gnu.org id=B20954.143584342011797 (code B ref 20954); Thu, 02 Jul 2015 13:24:02 +0000 Received: (at 20954) by debbugs.gnu.org; 2 Jul 2015 13:23:40 +0000 Received: from localhost ([127.0.0.1]:37050 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAeSp-00034C-Ue for submit@debbugs.gnu.org; Thu, 02 Jul 2015 09:23:40 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:37464) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAeSo-00033z-7V for 20954@debbugs.gnu.org; Thu, 02 Jul 2015 09:23:38 -0400 Received: by wicgi11 with SMTP id gi11so73710049wic.0 for <20954@debbugs.gnu.org>; Thu, 02 Jul 2015 06:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=+w3ES34pAKPDf43DRQ2xg9sm1gSn80/jNZmgyTpIgy8=; b=Os9m/ddDzmj1qitJnUiM/N96UsPvQZVa7lQDyWGAhjcNmg2qGzTDiNrZp1+sQoEWQ/ SUu4rM/ecZz5Ix4oS629xIQNTIWw04cm3OpvE1ffe7RuwQAiYgJELj6kRaRGQEhGlbPj VuhFkKFYHSwYvK7/k1b2FJ63lk2tIhRL20EeUkqY3KFhdRF5dQA7WqHcYhsOAf3iGYUQ FA0hKosrB9CmFDAp8HPHGGQVVNc5tsiudiFpMwh3/5hxahnBSoX4ZRRs3yWlYbpC0B4+ C7Gml5LpPa8LTbZHUZ/lItG1XPzabwcmDKIx1/CItZGSBZ/Ogy6gTRqU/Z87h8Tb5Jj8 Izjg== X-Received: by 10.194.173.8 with SMTP id bg8mr10685724wjc.65.1435843412524; Thu, 02 Jul 2015 06:23:32 -0700 (PDT) Received: from chaz.gmail.com ([2.217.126.102]) by mx.google.com with ESMTPSA id js3sm8190282wjc.5.2015.07.02.06.23.31 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 02 Jul 2015 06:23:31 -0700 (PDT) Date: Thu, 2 Jul 2015 14:23:30 +0100 From: Stephane Chazelas Message-ID: <20150702132330.GC7277@chaz.gmail.com> References: <55946B0E.3080000@wp.pl> <20150701193543368876542@bob.proulx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150701193543368876542@bob.proulx.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) 2015-07-01 19:41:00 -0600, Bob Proulx: [...] > > $ a="" ; echo $s | wc -l > > 1 [...] > No. Should be 1. You have forgotten about the newline at the end of > the command. The echo will terminate with a newline. [...] Leaving a variable unquoted will also cause the shell to apply the split+glob operator on it. echo will also do some transformations on the string (backslash and option processing). To count the number of bytes in a variable, you can use: printf %s "$var" | wc -c Use "${#var}" or printf %s "$var" | wc -m for the number of characters. GNU wc will not count the bytes that are not part of a valid character, while GNU bash's ${#var} will count them as one character: In a UTF-8 locale: $ var=$'\x80X\x80\u00e9' $ printf %s "$var" | hd 00000000 80 58 80 c3 a9 |.X...| 00000005 $ echo "${#var}" 4 $ printf %s "$var" | wc -c 5 $ printf %s "$var" | wc -m 2 Above $var contains the 0x80 byte that doesn't form a valid character, "X" (0x58), then another 0x80, then é (0xc3 0xa9). wc -c counts the 5 bytes, wc -m counts X and é, while bash ${#var} counts those plus the 0x80s. -- Stephane From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: tele Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 02 Jul 2015 15:30:19 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: 20954@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.143585101723660 (code B ref -1); Thu, 02 Jul 2015 15:30:19 +0000 Received: (at submit) by debbugs.gnu.org; 2 Jul 2015 15:30:17 +0000 Received: from localhost ([127.0.0.1]:37806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAgRG-00069G-DB for submit@debbugs.gnu.org; Thu, 02 Jul 2015 11:30:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35096) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAbbj-0005kQ-6P for submit@debbugs.gnu.org; Thu, 02 Jul 2015 06:20:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAbbd-0000Cd-0x for submit@debbugs.gnu.org; Thu, 02 Jul 2015 06:20:33 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:51979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAbbc-0000CW-UD for submit@debbugs.gnu.org; Thu, 02 Jul 2015 06:20:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAbbb-0008A4-U1 for bug-coreutils@gnu.org; Thu, 02 Jul 2015 06:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAbbX-000094-Ek for bug-coreutils@gnu.org; Thu, 02 Jul 2015 06:20:31 -0400 Received: from mx4.wp.pl ([212.77.101.12]:49916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAbbX-00008Y-3N for bug-coreutils@gnu.org; Thu, 02 Jul 2015 06:20:27 -0400 Received: (wp-smtpd smtp.wp.pl 27749 invoked from network); 2 Jul 2015 12:20:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1435832424; bh=bJcXINcqIkYKGjVySCCGjDIuqk61M6FNnE8QOsNJQRQ=; h=Subject:To:From; b=PaeESIFTTVqYcoSrerbwAaoFOoKKLmmY6xNhUgIwawoD4/RqS3uJt+X91DeXM+dP+ LtULXpWnrkwcew5Ir5eH/XGyw49FpbXiGwLCfpiQOOPyEtoWMq4JhTJi2OJOSqU8P2 2G4fKqzWvnDQPqR3262elWVNZOX3qtVWUaRCbUi8= Received: from dynamic-78-8-125-198.ssp.dialog.net.pl (HELO localhost.localdomain) (swojskichlopak@[78.8.125.198]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-SHA encrypted SMTP for ; 2 Jul 2015 12:20:24 +0200 References: <55946B0E.3080000@wp.pl> From: tele Message-ID: <5595104F.7000600@wp.pl> 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 MIME-Version: 1.0 In-Reply-To: <55946B0E.3080000@wp.pl> Content-Type: multipart/alternative; boundary="------------040200090007060508090403" X-WP-MailID: 01cd8cb023f2bbc80eda4976de3c867c X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000006 [kTZE] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Mailman-Approved-At: Thu, 02 Jul 2015 11:30:06 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) This is a multi-part message in MIME format. --------------040200090007060508090403 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 :-) --------------040200090007060508090403 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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 :-)
--------------040200090007060508090403-- From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: Bob Proulx Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 02 Jul 2015 23:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: tele Cc: 20954@debbugs.gnu.org Received: via spool by 20954-submit@debbugs.gnu.org id=B20954.14358800069031 (code B ref 20954); Thu, 02 Jul 2015 23:34:02 +0000 Received: (at 20954) by debbugs.gnu.org; 2 Jul 2015 23:33:26 +0000 Received: from localhost ([127.0.0.1]:38078 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAnyw-0002La-Bf for submit@debbugs.gnu.org; Thu, 02 Jul 2015 19:33:26 -0400 Received: from joseki.proulx.com ([216.17.153.58]:44974) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAnyu-0002LS-Ds for 20954@debbugs.gnu.org; Thu, 02 Jul 2015 19:33:24 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 9A2DE2183C; Thu, 2 Jul 2015 17:33:23 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 569F92DC4D; Thu, 2 Jul 2015 17:33:23 -0600 (MDT) Date: Thu, 2 Jul 2015 17:33:23 -0600 From: Bob Proulx Message-ID: <20150702171744337957028@bob.proulx.com> References: <55946B0E.3080000@wp.pl> <5595104F.7000600@wp.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5595104F.7000600@wp.pl> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.6 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) tele wrote: > "echo" gives in new line, Yes. > "echo -n" subtracts 1 line, echo -n is non-portable and shouldn't be used. echo -n suppresses emitting a trailing newline. Note that in both of these cases you are using the shell's internal builtin echo and not the coreutils echo. They behave the same. > but "wc -l" can count only from new line, so if something exist > inside first line "wc -l" can not count. :-( "wc -l" counts newlines. That is the task that it was constructed to do. That is exactly what it does. No more and no less. What is a text line? A text line by definition ends with a newline. This has been standardized to prevent different implementations from implementing it differently and creating portability problems. Therefore all standards compliant implementations must implement it in the same way to prevent portability problems. > example: > > $ a="j" ; echo "$a" | wc -l > 1 I have been wondering. Why are you using a variable here? Using the variable as you are doing is no different than not using the variable. echo "j" | od -tx1 -c 0000000 6a 0a j \n There is one newline. That counts as one text line. > $ a="" ; echo "$a" | wc -l > 1 echo "" | od -tx1 -c 0000000 0a \n There is one newline. That counts as one text line. > $ a="" ; echo -n "$a" | wc -l > 0 echo -n "" | od -tx1 -c 0000000 Nothing was emitted. No newlines. Counts as zero lines. But nothing was emitted. Zero characters. od -tx1 -c < /dev/null 0000000 > $ a="j" ; echo -n "$a" | wc -l > 0 echo -n "j" | od -tx1 -c 0000000 6a j That emits one character, the 'j' character. It emits no newlines. Without any newlines at all that is not and cannot be a "text" line. Without a newline that can only be interpreted as binary data. In any case there were no newlines to count and "wc -l" counted and reported zero newlines. Instead of echo -n it would be better and portable to use printf instead. printf "j" | od -tx1 -c 0000000 6a j Same action in a portable way using printf. Avoid using echo with options. > So, > > $ a="" ; echo "$a" | sed '/^\s*$/d' | wc -l > 0 echo "" | sed '/^\s*$/d' | od -tx1 -c 0000000 As we previosuly see the echo action will emit one newline character. This is piped to the sed program which will delete that line. Deleting the line is what the sed 'd' action does. Therefore sed does not emit the newline. The text line is deleted. > $ a="3" ; echo "$a" | sed '/^\s*$/d' | wc -l > 1 echo "3" | sed '/^\s*$/d' | od -tx1 -c 0000000 33 0a 3 \n Here the echo emitted two character a '3' and a newline. The sed prgram did not match and therefore did not delete the line. Since it did not delete the line it passed the one text line to wc and "wc -l" counted the one newline and reported one text line. > Can be added option to "wc" to fix this problem without use sed in future ? > Thanks for helping :-) There is no problem to be fixed. And therefore this isn't something that can be "fixed" in wc. Bob From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: tele Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Fri, 03 Jul 2015 14:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: 20954@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.143593311117816 (code B ref -1); Fri, 03 Jul 2015 14:19:02 +0000 Received: (at submit) by debbugs.gnu.org; 3 Jul 2015 14:18:31 +0000 Received: from localhost ([127.0.0.1]:38826 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZB1nS-0004dH-6u for submit@debbugs.gnu.org; Fri, 03 Jul 2015 10:18:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43247) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAwfR-0003v7-9f for submit@debbugs.gnu.org; Fri, 03 Jul 2015 04:49:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAwfL-0005cL-0R for submit@debbugs.gnu.org; Fri, 03 Jul 2015 04:49:47 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: ** X-Spam-Status: No, score=2.6 required=5.0 tests=BAYES_50,FREEMAIL_FROM, HTML_EMBEDS,HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:52434) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAwfK-0005cF-T9 for submit@debbugs.gnu.org; Fri, 03 Jul 2015 04:49:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAwfJ-0001rs-PS for bug-coreutils@gnu.org; Fri, 03 Jul 2015 04:49:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAwfD-0005Xs-E2 for bug-coreutils@gnu.org; Fri, 03 Jul 2015 04:49:45 -0400 Received: from mx4.wp.pl ([212.77.101.11]:57407) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAwfC-0005Tu-RL for bug-coreutils@gnu.org; Fri, 03 Jul 2015 04:49:39 -0400 Received: (wp-smtpd smtp.wp.pl 20547 invoked from network); 3 Jul 2015 10:49:35 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1435913375; bh=qgTKYpxbtEHUc0qamS8vx56qyw3JMQr2b39OgVUuAiQ=; h=Subject:To:From; b=v/fNHri7eKrBLNGbOa1XnELbfpx+BkzXYPlSilorNy4QCTj4GW586Bp1D4P1zqx6X VTnzDVORf3aNT8mKyMabAQI4y3cIUBRHf1veq8KLf0b7Jdg6wfvSY4K6CY+4jcFoH3 6KsWtxou2c9QymXH08Yn3T3I4ZPYgcDNvDiT+cm8= Received: from dynamic-78-8-62-14.ssp.dialog.net.pl (HELO localhost.localdomain) (swojskichlopak@[78.8.62.14]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-SHA encrypted SMTP for ; 3 Jul 2015 10:49:35 +0200 References: <55946B0E.3080000@wp.pl> From: tele Message-ID: <55964C86.4010103@wp.pl> Date: Fri, 3 Jul 2015 10:49:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <55946B0E.3080000@wp.pl> Content-Type: multipart/alternative; boundary="------------000104070400040606000009" X-WP-MailID: f4a905e2c8d0dd1414f93b71b7853637 X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [MQIM] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -4.1 (----) X-Mailman-Approved-At: Fri, 03 Jul 2015 10:18:28 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) This is a multi-part message in MIME format. --------------000104070400040606000009 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit tag 20954 + notabug close 20954 thanks Maybe we did not understand. I don't want change old definitions but create new option for wc or echo, because this above examples not make logic sense, ( and it I want fix, however with sed is also fixed ) however now Iunderstand that they work correctly in accordance with accepted principles. # What is a text line? A text line by definition ends with a newline. This has been standardized to prevent # different implementations from implementing it differently and creating portability problems. Therefore # all standards compliant implementations must implement it in the same way to prevent portability # problems. " wc -l " in most examples working correct, because it " echo " give's " \n " and "wc -l" count correct. I mentioned about "wc", because for me build option "wc -a" for "echo" or "echo -m" this is not important. Maybe exist hope for example create option "m" to echo , " echo -m " which not will from new line, but first line if variable is empty and from new line if is not empty ? example: echo -m "" | wc -l 0 echo -m "e" | wc -l 1 --------------000104070400040606000009 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
tag 20954 + notabug
close 20954
thanks


Maybe we did not understand.
I don't want change old definitions but create new option for wc or echo,
because this above examples not make logic sense,
( and it I want fix, however with sed is also fixed )
 however now I
understand that they work correctly in accordance with accepted principles.

#  What is a text line? A text line by definition ends with a newline. This has been standardized to prevent
#  different implementations from implementing it differently and creating portability problems. Therefore
#  all standards compliant implementations must implement it in the same way to prevent portability
#  problems.

" wc -l " in most examples working correct,
because it " echo "  give's " \n " and "wc -l" count correct.
I  mentioned about "wc", because for me build option "wc -a" for "echo"  or "echo -m"
this is not important.
Maybe exist hope for example create option "m" to echo  , " echo -m "
which not will from new line, but first line if variable is empty
and from new line if is not empty  ?

example:

echo -m "" | wc -l
0

echo -m "e" | wc -l
1
--------------000104070400040606000009-- From unknown Mon Jun 23 11:27:01 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20954: wc - linux Resent-From: Bob Proulx Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Mon, 06 Jul 2015 02:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20954 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: tele Cc: 20954@debbugs.gnu.org Received: via spool by 20954-submit@debbugs.gnu.org id=B20954.143615043230643 (code B ref 20954); Mon, 06 Jul 2015 02:41:02 +0000 Received: (at 20954) by debbugs.gnu.org; 6 Jul 2015 02:40:32 +0000 Received: from localhost ([127.0.0.1]:41265 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZBwKc-0007y1-Bb for submit@debbugs.gnu.org; Sun, 05 Jul 2015 22:40:31 -0400 Received: from joseki.proulx.com ([216.17.153.58]:36448) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZBwKZ-0007xs-Jy for 20954@debbugs.gnu.org; Sun, 05 Jul 2015 22:40:28 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id A727221232; Sun, 5 Jul 2015 20:40:26 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 93B002DC48; Sun, 5 Jul 2015 20:40:26 -0600 (MDT) Date: Sun, 5 Jul 2015 20:40:26 -0600 From: Bob Proulx Message-ID: <20150705201748996343755@bob.proulx.com> References: <55946B0E.3080000@wp.pl> <55964C86.4010103@wp.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55964C86.4010103@wp.pl> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.6 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) tele wrote: > Maybe we did not understand. > I don't want change old definitions but create new option for wc or echo, > because this above examples not make logic sense, What would such an option do? > ( and it I want fix, however with sed is also fixed ) Your original message asked if "echo | wc -l" should count 0 lines instead of 1 line. But the echo is going to produce one line and therefore it should be counted. In a later message you wrote using sed to delete blank lines so that only non-blank lines remained to be counted. > $ 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 ? This tells me that you as yet did not understand things yet. :-( I tried to explain this in more detail in my response to that message. The sed command you pulled from stackoverflow.com deletes blank lines. That is a good way to avoid counting blank lines. If I guess at what you are suggesting then it does not make sense to add an option to wc to count only non-blank lines. If you don't want to count blank lines then delete them first. There are an infinite number of possible things to count. There cannot be an infinite number of options implemented. And using sed to delete blank lines is the Right Way To Do Things. > however now Iunderstand that they work correctly in accordance with > accepted principles. Yes. > > What is a text line? A text line by definition ends with a > > newline. This has been standardized to prevent different > > implementations from implementing it differently and creating > > portability problems. Therefore all standards compliant > > implementations must implement it in the same way to prevent > > portability problems. > > " wc -l " in most examples working correct, "most"? No. "wc -l" is working correctly in all examples. :-) > because it " echo " give's " \n " and "wc -l" count correct. Yes. > I mentioned about "wc", because for me build option "wc -a" for "echo" or > "echo -m" > this is not important. > Maybe exist hope for example create option "m" to echo , " echo -m " > which not will from new line, but first line if variable is empty > and from new line if is not empty ? > > example: > > echo -m "" | wc -l > 0 > > echo -m "e" | wc -l > 1 The shell is a programming language. If not infinite number then a very large number of possibilities may be implemented by programming them in the shell. All such possibilities should not be coded into specific options. Instead if you have a specific need it should be programmed. Simply write the code that says explicitly what you want to do. There are millions of lines of code written for various tasks. All of those millions of lines should not be turned into specific options. If you want to delete blank lines then simply delete blank lines. This entire discussion feels like an XY problem. Here is a collection of explanations of the XY problem. http://www.perlmonks.org/?node_id=542341 The help-bash@gnu.org mailing list is the right place to follow up but if you wrote there and said what you were trying to do and asking how to do it in the shell people would try to help you there. Bob