Subject: Re: bug#73402: Switch scripts from using `type` to `command -v` to support non-XSI POSIX shells, or specify bash?
From: Paul Eggert <[email-masked]>
To: Sparr <[email-masked]>
Cc: [email-masked]
Date: Sun, 22 Sep 2024 00:09:24 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Thanks for the bug report. I installed the attached patch to fix the bug 
and am boldly closing the bug report. If the patch doesn't work for you, 
please let us know and we can reopen the bug report.

From 602fa20438cddaa8ede84828b6fbe42a06d49392 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sun, 22 Sep 2024 00:06:44 -0700
Subject: [PATCH] =?UTF-8?q?maint:=20=E2=80=98type=E2=80=99=20=E2=86=92=20?=
 =?UTF-8?q?=E2=80=98command=20-v=E2=80=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

POSIX says ‘type’ is an XSI extension, whereas ‘command -v’ is
part of the base.  Problem reported by Clarence “Sparr” Risher in
<https://bugs.gnu.org/73402>.
* gzexe.in, tests/help-version, zdiff.in, zgrep.in:
Use ‘command -v’, not ‘type’.
---
 gzexe.in           | 4 ++--
 tests/help-version | 2 +-
 zdiff.in           | 2 +-
 zgrep.in           | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gzexe.in b/gzexe.in
index 4504d77..217381d 100644
--- a/gzexe.in
+++ b/gzexe.in
@@ -116,7 +116,7 @@ for i do
   test -d "$dir" && test -w "$dir" && test -x "$dir" || dir=/tmp
   test -n "$tmp" && rm -f "$tmp"
   if test -z "$mktemp_status"; then
-    type mktemp >/dev/null 2>&1
+    command -v mktemp >/dev/null 2>&1
     mktemp_status=$?
   fi
   case $dir in
@@ -166,7 +166,7 @@ case $TMPDIR in
   /*) TMPDIR=$TMPDIR/;;
   *) TMPDIR=/tmp/;;
 esac
-if type mktemp >/dev/null 2>&1; then
+if command -v mktemp >/dev/null 2>&1; then
   gztmpdir=`mktemp -d "${TMPDIR}gztmpXXXXXXXXX"`
 else
   gztmpdir=${TMPDIR}gztmp$$; mkdir $gztmpdir
diff --git a/tests/help-version b/tests/help-version
index 809d958..3b2fe03 100755
--- a/tests/help-version
+++ b/tests/help-version
@@ -255,7 +255,7 @@ for i in $built_programs; do
   mkdir $tmp_dir
   # echo ================== $i
   test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//")
-  if type ${prog}_setup > /dev/null 2>&1; then
+  if command -v ${prog}_setup > /dev/null 2>&1; then
     ${prog}_setup
   else
     args=
diff --git a/zdiff.in b/zdiff.in
index a76e91b..38f83db 100644
--- a/zdiff.in
+++ b/zdiff.in
@@ -155,7 +155,7 @@ case $file2 in
                           /*) TMPDIR=$TMPDIR/;;
                           *) TMPDIR=/tmp/;;
                         esac
-                        if type mktemp >/dev/null 2>&1; then
+                        if command -v mktemp >/dev/null 2>&1; then
                           tmp=`mktemp "${TMPDIR}zdiffXXXXXXXXX"` ||
                             exit 2
                         else
diff --git a/zgrep.in b/zgrep.in
index ab80d56..acb5168 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -142,7 +142,7 @@ while test $# -ne 0; do
         /*) TMPDIR=$TMPDIR/;;
         *) TMPDIR=/tmp/;;
       esac
-      if type mktemp >/dev/null 2>&1; then
+      if command -v mktemp >/dev/null 2>&1; then
         pattmp=$(mktemp "${TMPDIR}zgrepXXXXXXXXX") || exit 2
       else
         set -C
-- 
2.43.0