From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nikolay Shaplov <dhyan@nataraj.su>
Cc: pgsql-hackers@lists.postgresql.org, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Витус Вагнер <vitus@wagner.pp.ru>
Subject: Re: [PATCH] check for ctags utility in make_ctags
Date: Sun, 06 Jan 2019 12:16:07 -0500
Message-ID: <5709.1546794967@sss.pgh.pa.us> (raw)
In-Reply-To: <96675367.WEgyTzNvEp@x200m>
References: <2394207.ccz7JgCJsh@x200m>
<2205856.meAnofT0VS@x200m>
<364f4cb7-4f1f-516e-d27e-59578b7cf18c@2ndquadrant.com>
<96675367.WEgyTzNvEp@x200m>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, dhyan@nataraj.su, peter.eisentraut@2ndquadrant.com, michael@paquier.xyz, vitus@wagner.pp.ru
Subject: Re: [PATCH] check for ctags utility in make_ctags
In-Reply-To: <5709.1546794967@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox