From: Eric Sunshine Date: Mon, 12 Apr 2021 18:48:43 GMT Subject: Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/|| Message-ID: In-Reply-To: On Mon, Apr 12, 2021 at 2:38 PM Junio C Hamano wrote: > Eric Sunshine writes: > >> + /\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"'; > >> + /\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"'; > > > > These will only match the simplistic forms of `test -X blah` (where > > "-X" is some single letter option), but will miss expressions such as > > `test "$foo" = bar`. Crafting a regex to match more generally would be > > non-trivial, so this simpler match is a reasonable start. Okay. > > Would it be a trivial improvement to do > > 'test', followed by anything other than '&' or '|', and then > followed by '-a' or '-o' > > instead? That seems plausible and trivial enough. In fact, I think it eliminates a source of false-positives that Ævar's pattern can report, such as: test whatever && ls -a foo and test whatever && foo -o outfile among others.