Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Eric Sunshine" <sunshine@xxxxxxxxxxxxxx> wrote:

> On Mon, Apr 12, 2021 at 7:09 AM Ævar Arnfjörð Bjarmason
> <avarab@xxxxxxxxx> 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/



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux