File: deprecate-which

package info (click to toggle)
check-postgres 2.25.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,016 kB
  • sloc: perl: 12,307; sh: 18; makefile: 13
file content (34 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
commit 6fb2c997dd7bcbdc6f36dced60ccc82fb01a6d2f
Author: Christoph Berg <christoph.berg@credativ.de>
Date:   Thu Sep 9 16:52:22 2021 +0200

    Debian deprecates `which`, use POSIX standard `command -v` instead
    
    debianutils (5.3-1) unstable; urgency=medium
    
      * The 'which' utility will be removed in the future.  Shell scripts
        often use it to check whether a command is available.  A more
        standard way to do this is with 'command -v'; for example:
          if command -v update-icon-caches >/dev/null; then
            update-icon-caches /usr/share/icons/...
          fi
        '2>/dev/null' is unnecessary when using 'command': POSIX says "no
        output shall be written" if the command isn't found.  It's also
        unnecessary for the debianutils version of 'which', and hides the
        deprecation warning.
    
     -- Clint Adams <clint@debian.org>  Fri, 20 Aug 2021 07:22:18 -0400

diff --git a/check_postgres.pl b/check_postgres.pl
index ba28f27..be5ccdb 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -2090,7 +2090,7 @@ if (exists $opt{PSQL}) {
 }
 else {
     my $psql = (defined $PGBINDIR) ? "$PGBINDIR/psql" : 'psql';
-    chomp($PSQL = qx{which "$psql"});
+    chomp($PSQL = qx{command -v "$psql"});
     $PSQL or ndie msg('opt-psql-nofind');
 }
 -x $PSQL or ndie msg('opt-psql-noexec', $PSQL);