Re: [PATCH] check for ctags utility in make_ctags - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCH] check for ctags utility in make_ctags
Date
Msg-id 5709.1546794967@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCH] check for ctags utility in make_ctags  (Nikolay Shaplov <dhyan@nataraj.su>)
Responses Re: [PATCH] check for ctags utility in make_ctags  (Andrew Dunstan <andrew.dunstan@2ndquadrant.com>)
List pgsql-hackers
Nikolay Shaplov <dhyan@nataraj.su> writes:
> В письме от четверг, 3 января 2019 г. 12:52:36 MSK пользователь Peter
> Eisentraut написал:
>> I don't know how portable command -v is.  Some systems have a /bin/sh
>> that is pre-POSIX.  Same with $(...).

> Do you know how to obtain such a shell in Debian?

TBH, when I first saw this patch, I had the same reaction as Peter,
ie I wondered how portable this was.  However, upon investigation:

1. "command -v <something>" is specified by Single Unix Spec v2,
which we've considered as our baseline portability requirement
for a good long time now.

2. Even my pet dinosaur HPUX 10.20 box recognizes it.  I do not
believe anybody working on PG these days is using something older.

3. These scripts aren't part of any build or runtime process,
they're only useful for development.  We've long felt that it's
okay to have higher requirements for development environments
than for production.  Besides, do you really think anybody's
going to be doing PG v12+ development on a box with a pre-SUSv2
shell and a C99 compiler?

We need not get into the question of whether $(...) is portable,
because the way it's being used is not: if command -v does not
find the target command, it prints nothing, so that at least
some systems will do this:

$ if [ ! $(command -v notetags) ]
> then
> echo not found
> fi
ksh: test: argument expected

(I'm not very sure why bash fails to act that way, actually.
"!" with nothing after it shouldn't be valid syntax for test(1),
you'd think.)

The correct way to code this is to depend on the exit code,
not the text output:

if command -v etags >/dev/null
then
  : ok
else
  echo etags not found
  exit 1
fi

We could alternatively try to use "which" in the same way,
but I'm dubious that it's more portable than "command".
(AFAICT, "which" is *not* in POSIX.)

            regards, tom lane


pgsql-hackers by date:

Previous
From: Nikolay Shaplov
Date:
Subject: Re: [PATCH][PROPOSAL] Add enum releation option type
Next
From: Fabien COELHO
Date:
Subject: Re: [HACKERS] pgbench - allow to store select results intovariables