Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
"Eric Sunshine" <sunshine@sunshineco.com> wrote:
Show 5 quoted lines
> On Mon, Apr 12, 2021 at 7:09 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
> > Expand the t/check-non-portable-shell.pl checks to complain about the
> > use of "-a" and "-o" to the "test" shell built-in to to mean "and" and
> > "or", as opposed to using two "test" invocations with "&&" or "||".
> > There aren't any portability issues with using that construct that I
> > know of, but since Junio expressed a dislike of it in [1] and we've
> > currently got no such constructs let's add it to the lint checking. I
> > had various in-flight and WIP patches that used this construct.
> It's not only Junio's dislike of `-a` and `-o` but also that they have
> long been considered obsolescent by POSIX[1]. GNU has likewise warned
> against it[2] for a few decades.
> [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
And also in Git's Documentation/CodingGuidelines, which motivates the advice with an example:
test -n "$x" -a "$a" = "$b"
is buggy and breaks when $x is "=", but
test -n "$x" && test "$a" = "$b"
does not have such a problem.
--
Matthieu Moy
https://matthieu-moy.fr/