Add a check for -a/-o in "test", as a follow-up to the CodingGuidelines having recommended against their use since 897f964c0dc (CodingGuidelines: avoid "test <cond> -a/-o <cond>", 2014-05-20). These constructs are considered obsolescent by POSIX[1]. GNU has likewise warned against them[2] for a few decades. 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 1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16 2. https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Limitations-of-Builtins.html Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- t/check-non-portable-shell.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index fd3303552b..894aa0a4f9 100755 --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -41,6 +41,8 @@ sub err { /^\s*declare\s+/ and err 'arrays/declare not portable'; /^\s*[^#]\s*which\s/ and err 'which is not portable (use type)'; /\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)'; + /\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"'; /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)'; /\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES <file >out)'; /(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)'; -- 2.31.1.723.gf6bad1b9ba1