git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v1 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable

From
tboegi@web.de <tboegi@web.de>
Date
Dec 10, 2017, 10:50 UTC
Message-ID
<20171210105013.3984-1-tboegi@web.de>
In-Reply-To
<xmqqh8t2ckgw.fsf@gitster.mtv.corp.google.com>
From: Torsten Bögershausen <tboegi@web.de>
wc -l is used to count the number if lines in test scripts.
$ wc -l Makefile
gives a line like this:
105 Makefile
while Mac OS has 4 leading spaces:
     105 Makefile

And this means that shell expressions like test "$(wc -l <expect)" = "4" don't work under Mac OS,

A portable way to use `wc -l` is to omit the '"': test $(wc -l <expect) = "4"

Add a check in check-non-portable-shell.pl to find '"' between `wc -l` and '='

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 t/check-non-portable-shell.pl | 1 +
 1 file changed, 1 insertion(+)
diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
index 03dc9d2852..9ebf65c26f 100755
--- a/t/check-non-portable-shell.pl
+++ b/t/check-non-portable-shell.pl
@@ -21,6 +21,7 @@ while (<>) {
 	/^\s*declare\s+/ and err 'arrays/declare not portable';
 	/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
 	/\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
+	/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable, please use `$(wc -l)`';
 	/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
 	# this resets our $. for each file
 	close ARGV if eof;
-- 
2.15.1.271.g1a4e40aa5d
Previous: Junio C HamanoNext: Johannes Schindelin
Message 16 of 26 in “What's cooking in git.git (Dec 2017, #01; Mon, 4)”
  1. Junio C HamanoDec 4, 2017
  2. Jeff HostetlerDec 4, 2017
  3. Elijah NewrenDec 4, 2017
  4. Jonathan TanDec 4, 2017
  5. Junio C HamanoDec 5, 2017
  6. Lars SchneiderDec 6, 2017
  7. Torsten BögershausenDec 6, 2017
  8. Junio C HamanoDec 6, 2017
  9. Johannes SchindelinDec 7, 2017
  10. Todd ZullingerDec 7, 2017
  11. Junio C HamanoDec 7, 2017
  12. Lars SchneiderDec 7, 2017
  13. Junio C HamanoDec 7, 2017
  14. Jeff HostetlerDec 7, 2017
  15. Junio C HamanoDec 7, 2017
  16. 1/1 check-non-portable-shell.pl: Quoted `wc -l` is not portabletboegi@web.de, Dec 10, 2017
  17. Johannes SchindelinDec 10, 2017
  18. Junio C HamanoDec 11, 2017
  19. 1/1 check-non-portable-shell.pl: Quoted `wc -l` is not portabletboegi@web.de, Dec 16, 2017
  20. Eric SunshineDec 17, 2017
  21. 1/1 check-non-portable-shell.pl: Quoted `wc -l` is not portabletboegi@web.de, Dec 21, 2017
  22. Junio C HamanoDec 22, 2017
  23. Torsten BögershausenDec 23, 2017
  24. Todd ZullingerDec 7, 2017
  25. Torsten BögershausenDec 9, 2017
  26. Johannes SchindelinDec 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.