From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "Torsten Bögershausen" <tboegi@web.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v1 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable
Date: Sun, 10 Dec 2017 14:59:45 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.21.1.1712101458150.4318@virtualbox> (raw)
In-Reply-To: <20171210105013.3984-1-tboegi@web.de>
[-- Attachment #1: Type: text/plain, Size: 1731 bytes --]
Hi Torsten,
On Sun, 10 Dec 2017, tboegi@web.de wrote:
> 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;
As noted elsewhere, this should suggest `test_line_count` instead. After
all, that function is not only guaranteed to stay portable (even if we
should ever start supporting systems *without* `wc`), but it also has a
semantically-meaningful name worthy of the current century.
Ciao,
Dscho
next prev parent reply other threads:[~2017-12-10 14:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-04 21:46 What's cooking in git.git (Dec 2017, #01; Mon, 4) Junio C Hamano
2017-12-04 22:04 ` Jeff Hostetler
2017-12-04 22:26 ` Elijah Newren
2017-12-04 23:46 ` Jonathan Tan
2017-12-05 0:30 ` Junio C Hamano
2017-12-06 15:14 ` Lars Schneider
2017-12-06 16:03 ` Torsten Bögershausen
2017-12-06 16:48 ` Junio C Hamano
2017-12-07 15:48 ` Johannes Schindelin
2017-12-07 20:22 ` Todd Zullinger
2017-12-07 20:50 ` Junio C Hamano
2017-12-07 21:08 ` Lars Schneider
2017-12-07 21:21 ` Junio C Hamano
2017-12-07 21:08 ` Jeff Hostetler
2017-12-07 21:10 ` Junio C Hamano
2017-12-10 10:50 ` [PATCH v1 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable tboegi
2017-12-10 13:59 ` Johannes Schindelin [this message]
2017-12-11 23:07 ` Junio C Hamano
2017-12-16 19:52 ` [PATCH v2 " tboegi
2017-12-17 0:06 ` Eric Sunshine
2017-12-21 21:26 ` [PATCH v3 " tboegi
2017-12-22 21:07 ` Junio C Hamano
2017-12-23 7:27 ` Torsten Bögershausen
2017-12-07 21:33 ` What's cooking in git.git (Dec 2017, #01; Mon, 4) Todd Zullinger
2017-12-09 14:46 ` Torsten Bögershausen
2017-12-10 13:50 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.21.1.1712101458150.4318@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox