Re: [PATCH] check for ctags utility in make_ctags

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nikolay Shaplov <dhyan(at)nataraj(dot)su>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Витус Вагнер <vitus(at)wagner(dot)pp(dot)ru>
Subject: Re: [PATCH] check for ctags utility in make_ctags
Date: 2019-01-06 17:16:07
Message-ID: 5709.1546794967@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nikolay Shaplov <dhyan(at)nataraj(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2019-01-06 18:29:45 Re: [HACKERS] pgbench - allow to store select results into variables
Previous Message Nikolay Shaplov 2019-01-06 15:28:11 Re: [PATCH][PROPOSAL] Add enum releation option type