Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 20, 2021, 22:25 UTC
- Message-ID
- <xmqqwnsw3872.fsf@gitster.g>
- In-Reply-To
- <patch-01.12-a8b483bc77-20210420T121833Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 7 quoted lines
> 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`. We stop at "&" or "|" to try not to overmatch > things like: > > test whatever && ls -a foo > test whatever && foo -o outfile
I still do not understand why you have to insist on dashed operator as the first thing given to "test", like this:
> + /\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" ... > + /\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" ...
IOW, what over-matching would we get if we simplified the condition like so?
/\btest\s+[^&|]+\s+-a\s/
/\btest\s+[^&|]+\s+-o\s/The one in the patch would miss things like
test "$a" = "$b" -o "$a" -lt "$b" test "$n" -a "$n" -lt 4
but the only thing that we care about is that a command that started with "test " has "-a" or "-o" before we see "&" or "|", no?