maint: script diagnostics status cleanup
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Nov 2017 07:02:02 +0000 (23:02 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Nov 2017 07:11:07 +0000 (23:11 -0800)
Problem reported by Bruno Haible (Bug#29266#20).
* NEWS: Mention this.
* gunzip.in, gzexe.in, zcat.in, zcmp.in, zdiff.in, zforce.in:
* zgrep.in, zless.in, zmore.in, znew.in:
Use printf instead of echo if the argument might contain ‘\’, at
least in theory.  Don’t assume printf exits with status 1 on
failure; it might be some other positive status.
* gzexe.in: Use printf consistently instead of echo, and
proscribe it instead of echo.

NEWS
gunzip.in
gzexe.in
zcat.in
zcmp.in
zdiff.in
zforce.in
zgrep.in
zless.in
zmore.in
znew.in

diff --git a/NEWS b/NEWS
index 34eae0ddc687bf3745e63fc0f09178b3c5b1dd55..68af1dc12a7328085445922e1b27deb0c5756be1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,11 @@ GNU gzip NEWS                                    -*- outline -*-
   1970 and after 2106, and timestamps after 2038 on platforms with
   32-bit signed time_t.  [bug present since the beginning]
 
+  Commands implemented via shell scripts are now more consistent about
+  failure status.  For example, 'gunzip --help >/dev/full' now
+  consistently exits with status 1 (error), instead of with status 2
+  (warning) on some platforms.  [bug present since the beginning]
+
   Support for VMS and Amiga has been removed.  It was not working anyway,
   and it reportedly caused file name glitches on MS-Windowsish platforms.
 
index a5dfb89a59302f552e478619db4b234ffb6528a8..0602724f48e8b7a7414cedf725b313e8f6ae9437 100644 (file)
--- a/gunzip.in
+++ b/gunzip.in
@@ -50,8 +50,8 @@ With no FILE, or when FILE is -, read standard input.
 Report bugs to <bug-gzip@gnu.org>."
 
 case $1 in
---help)    exec echo "$usage";;
---version) exec echo "$version";;
+--help)    printf '%s\n' "$usage"   || exit 1; exit;;
+--version) printf '%s\n' "$version" || exit 1; exit;;
 esac
 
 exec gzip -d "$@"
index 87413a35afd4f361a5da25b8de34e037975bf27c..290fa1cba4264f66bb6d890610ca9c7f95528884 100644 (file)
--- a/gzexe.in
+++ b/gzexe.in
@@ -59,15 +59,15 @@ res=0
 while :; do
   case $1 in
   -d) decomp=1; shift;;
-  --h*) exec echo "$usage";;
-  --v*) exec echo "$version";;
+  --h*) printf '%s\n' "$usage"   || exit 1; exit;;
+  --v*) printf '%s\n' "$version" || exit 1; exit;;
   --) shift; break;;
   *) break;;
   esac
 done
 
 if test $# -eq 0; then
-  echo >&2 "$0: missing operand
+  printf >&2 '%s\n' "$0: missing operand
 Try \`$0 --help' for more information."
   exit 1
 fi
@@ -87,29 +87,29 @@ for i do
   esac
   if test ! -f "$file" || test ! -r "$file"; then
     res=$?
-    echo >&2 "$0: $i is not a readable regular file"
+    printf >&2 '%s\n' "$0: $i is not a readable regular file"
     continue
   fi
   if test $decomp -eq 0; then
     if sed -e 1d -e 2q "$file" | grep "^skip=[0-9][0-9]*$" >/dev/null; then
-      echo >&2 "$0: $i is already gzexe'd"
+      printf >&2 '%s\n' "$0: $i is already gzexe'd"
       continue
     fi
   fi
   if test -u "$file"; then
-    echo >&2 "$0: $i has setuid permission, unchanged"
+    printf >&2 '%s\n' "$0: $i has setuid permission, unchanged"
     continue
   fi
   if test -g "$file"; then
-    echo >&2 "$0: $i has setgid permission, unchanged"
+    printf >&2 '%s\n' "$0: $i has setgid permission, unchanged"
     continue
   fi
   case /$file in
   */basename | */bash | */cat | */chmod | */cp | \
-  */dirname | */echo | */expr | */gzip | \
-  */ln | */mkdir | */mktemp | */mv | */rm | \
+  */dirname | */expr | */gzip | \
+  */ln | */mkdir | */mktemp | */mv | */printf | */rm | \
   */sed | */sh | */sleep | */test | */tail)
-    echo >&2 "$0: $i might depend on itself"; continue;;
+    printf >&2 '%s\n' "$0: $i might depend on itself"; continue;;
   esac
 
   dir=`dirname "$file"` || dir=$TMPDIR
@@ -125,7 +125,7 @@ for i do
     tmp=$dir/gzexe$$
   fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || {
     res=$?
-    echo >&2 "$0: cannot copy $file"
+    printf >&2 '%s\n' "$0: cannot copy $file"
     continue
   }
   if test -w "$tmp"; then
@@ -134,7 +134,7 @@ for i do
     writable=0
     chmod u+w "$tmp" || {
       res=$?
-      echo >&2 "$0: cannot chmod $tmp"
+      printf >&2 '%s\n' "$0: cannot chmod $tmp"
       continue
     }
   fi
@@ -170,7 +170,7 @@ case $0 in
 */*) gztmp=$gztmpdir/`basename "$0"`;;
 esac || { (exit 127); exit 127; }
 
-case `echo X | tail -n +1 2>/dev/null` in
+case `printf 'X\n' | tail -n +1 2>/dev/null` in
 X) tail_n=-n;;
 *) tail_n=;;
 esac
@@ -180,13 +180,13 @@ if tail $tail_n +$skip <"$0" | gzip -cd > "$gztmp"; then
   (sleep 5; rm -fr "$gztmpdir") 2>/dev/null &
   "$gztmp" ${1+"$@"}; res=$?
 else
-  echo >&2 "Cannot decompress $0"
+  printf >&2 '%s\n' "Cannot decompress $0"
   (exit 127); res=127
 fi; exit $res
 EOF
     gzip -cv9 "$file") > "$tmp" || {
       res=$?
-      echo >&2 "$0: compression not possible for $i, file unchanged."
+      printf >&2 '%s\n' "$0: compression not possible for $i, file unchanged."
       continue
     }
 
@@ -198,29 +198,29 @@ EOF
     skip=[0-9] | skip=[0-9][0-9] | skip=[0-9][0-9][0-9])
       eval "$skip_line";;
     esac
-    case `echo X | tail -n +1 2>/dev/null` in
+    case `printf 'X\n' | tail -n +1 2>/dev/null` in
     X) tail_n=-n;;
     *) tail_n=;;
     esac
     tail $tail_n +$skip "$file" | gzip -cd > "$tmp" || {
       res=$?
-      echo >&2 "$0: $i probably not in gzexe format, file unchanged."
+      printf >&2 '%s\n' "$0: $i probably not in gzexe format, file unchanged."
       continue
     }
   fi
   test $writable -eq 1 || chmod u-w "$tmp" || {
     res=$?
-    echo >&2 "$0: $tmp: cannot chmod"
+    printf >&2 '%s\n' "$0: $tmp: cannot chmod"
     continue
   }
   ln -f "$file" "$file~" || {
     res=$?
-    echo >&2 "$0: cannot backup $i as $i~"
+    printf >&2 '%s\n' "$0: cannot backup $i as $i~"
     continue
   }
   mv -f "$tmp" "$file" || {
     res=$?
-    echo >&2 "$0: cannot rename $tmp to $i"
+    printf >&2 '%s\n' "$0: cannot rename $tmp to $i"
     continue
   }
   tmp=
diff --git a/zcat.in b/zcat.in
index 524ac513586fb9c6879c0a6b98722aab041197ec..9cf4c2d7c7e7d09c19b0b225f6f16f3beb136ebc 100644 (file)
--- a/zcat.in
+++ b/zcat.in
@@ -44,8 +44,8 @@ With no FILE, or when FILE is -, read standard input.
 Report bugs to <bug-gzip@gnu.org>."
 
 case $1 in
---help)    exec echo "$usage";;
---version) exec echo "$version";;
+--help)    printf '%s\n' "$usage"   || exit 1; exit;;
+--version) printf '%s\n' "$version" || exit 1; exit;;
 esac
 
 exec gzip -cd "$@"
diff --git a/zcmp.in b/zcmp.in
index 784735088bc37412994c238b7cd3c1522b4b775d..b0a4ca245ef9af026a426e66327f42e7c476ddce 100644 (file)
--- a/zcmp.in
+++ b/zcmp.in
@@ -36,10 +36,9 @@ If a FILE is '-' or missing, read standard input.
 
 Report bugs to <bug-gzip@gnu.org>."
 
-st=0
 case $1 in
---help)    echo "$usage" || st=2; exit $st;;
---version) echo "$version" || st=2; exit $st;;
+--help)    printf '%s\n' "$usage"   || exit 2; exit;;
+--version) printf '%s\n' "$version" || exit 2; exit;;
 esac
 
 exec zdiff --__cmp "$@"
index e1efc1ed1bc1e87dacdc7ac8f80d6bc9b872f7b5..0d1e74967c4177b50e4bd795e7b12e6928d568d3 100644 (file)
--- a/zdiff.in
+++ b/zdiff.in
@@ -50,8 +50,8 @@ escape='
 
 while :; do
   case $1 in
-  --h*) printf '%s\n' "$usage" || exit 2; exit;;
-  --v*) echo "$version" || exit 2; exit;;
+  --h*) printf '%s\n' "$usage"   || exit 2; exit;;
+  --v*) printf '%s\n' "$version" || exit 2; exit;;
   --) shift; break;;
   -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
   -?*) cmp="$cmp '$1'";;
@@ -78,7 +78,7 @@ if test $# -eq 1; then
       (gzip -cd -- "$1" 4>&-; echo $? >&4) 3>&- | eval "$cmp" - '"$FILE"' >&3
     );;
   *)
-    echo >&2 "$0: $1: unknown compressed file extension"
+    printf >&2 '%s\n' "$0: $1: unknown compressed file extension"
     exit 2;;
   esac
 elif test $# -eq 2; then
@@ -152,7 +152,8 @@ elif test $# -eq 2; then
                 esac;;
         esac
 else
-        echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
+        printf >&2 '%s\n' \
+          "$0: invalid number of operands; try \`$0 --help' for help"
         exit 2
 fi
 
index 1770af314639555121812cb5afe5663bd741bbba..f0ff71ca3cc9048df6d05afb7691a65c184806d8 100644 (file)
--- a/zforce.in
+++ b/zforce.in
@@ -38,20 +38,20 @@ not compress them twice.
 Report bugs to <bug-gzip@gnu.org>."
 
 if test $# = 0; then
-  echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
+  printf >&2 '%s\n' "$0: invalid number of operands; try \`$0 --help' for help"
   exit 1
 fi
 
 res=0
 for i do
   case "$i" in
-  --h*) exec echo "$usage";;
-  --v*) exec echo "$version";;
+  --h*) printf '%s\n' "$usage"  ; exit;;
+  --v*) printf '%s\n' "$version"; exit;;
   *[-.]z | *[-.]gz | *.t[ag]z) continue;;
   esac
 
   if test ! -f "$i" ; then
-    echo zforce: $i not a file
+    printf '%s\n' "zforce: $i not a file"
     res=1
     continue
   fi
@@ -60,7 +60,7 @@ for i do
 
     new="$i.gz"
     if mv "$i" "$new"; then
-      echo $i -- replaced with $new
+      printf '%s\n' "$i -- replaced with $new"
     else
       res=$?
     fi
index 2ed007bf014119572e7f5d4bddf1b21db3eb33df..0660634dd4ad9c13c69de3bba8355321e4a1f505 100644 (file)
--- a/zgrep.in
+++ b/zgrep.in
@@ -144,7 +144,7 @@ while test $# -ne 0; do
     fi
     have_pat=1;;
   (--h | --he | --hel | --help)
-    echo "$usage" || exit 2
+    printf '%s\n' "$usage" || exit 2
     exit;;
   (-H | --wi | --wit | --with | --with- | --with-f | --with-fi \
   | --with-fil | --with-file | --with-filen | --with-filena | --with-filenam \
@@ -158,7 +158,7 @@ while test $# -ne 0; do
   (-h | --no-f*)
     no_filename=1;;
   (-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
-    echo "$version" || exit 2
+    printf '%s\n' "$version" || exit 2
     exit;;
   esac
 
index 9a3f399d5d37c36942b7240b5b45518a15b531f3..5c20d8271382d4035189b34ede2897f867afc0a4 100644 (file)
--- a/zless.in
+++ b/zless.in
@@ -32,8 +32,8 @@ Options are the same as for 'less'.
 Report bugs to <bug-gzip@gnu.org>."
 
 case $1 in
---help)    exec echo "$usage";;
---version) exec echo "$version";;
+--help)    printf '%s\n' "$usage"  ; exit;;
+--version) printf '%s\n' "$version"; exit;;
 esac
 
 if test "${LESSMETACHARS+set}" != set; then
index 1c9cebb3dea1e4bcd9f05888a53f538d8bfdb5a1..1bd3bdb737459d506c5e4f760551ca156d0b27e8 100644 (file)
--- a/zmore.in
+++ b/zmore.in
@@ -31,8 +31,8 @@ Like 'more', but operate on the uncompressed contents of any compressed FILEs.
 Report bugs to <bug-gzip@gnu.org>."
 
 case $1 in
-  --h*) exec printf '%s\n' "$usage";;
-  --v*) exec printf '%s\n' "$version";;
+  --h*) printf '%s\n' "$usage"  ; exit;;
+  --v*) printf '%s\n' "$version"; exit;;
   --) shift;;
   -?*) printf >&2 '%s\n' "$0: $1: unknown option; try '$0 --help' for help"
        exit 1;;
diff --git a/znew.in b/znew.in
index 29038df5c9451284cd77649c1e737830c83e1a11..5c98256e4396084f70d2a6c0b4fb3a48988167b2 100644 (file)
--- a/znew.in
+++ b/znew.in
@@ -60,8 +60,8 @@ ext=.gz
 for arg
 do
   case "$arg" in
-  --help)      exec echo "$usage";;
-  --version)   exec echo "$version";;
+  --help)      printf '%s\n' "$usage"  ; exit;;
+  --version)   printf '%s\n' "$version"; exit;;
   -*)     opt="$opt $arg"; shift;;
    *)     break;;
   esac
@@ -72,24 +72,24 @@ if test $# -eq 0; then
   exit 1
 fi
 
-opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
+opt=`printf '%s\n' "$opt" | sed -e 's/ //g' -e 's/-//g'`
 case "$opt" in
-  *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
+  *t*) check=1; opt=`printf '%s\n' "$opt" | sed 's/t//g'`
 esac
 case "$opt" in
-  *K*) keep=1; check=1; opt=`echo "$opt" | sed 's/K//g'`
+  *K*) keep=1; check=1; opt=`printf '%s\n' "$opt" | sed 's/K//g'`
 esac
 case "$opt" in
-  *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
+  *P*) pipe=1; opt=`printf '%s\n' "$opt" | sed 's/P//g'`
 esac
 if test -n "$opt"; then
   opt="-$opt"
 fi
 
 for i do
-  n=`echo "$i" | sed 's/.Z$//'`
+  n=`printf '%s\n' "$i" | sed 's/.Z$//'`
   if test ! -f "$n.Z" ; then
-    echo "$n.Z not found"
+    printf '%s\n' "$n.Z not found"
     res=1; continue
   fi
   test $keep -eq 1 && old=`wc -c < "$n.Z"`
@@ -99,7 +99,7 @@ for i do
       touch -r"$n.Z" -- "$n$ext" 2>/dev/null
       chmod --reference="$n.Z" -- "$n$ext" 2>/dev/null
     else
-      echo "error while recompressing $n.Z"
+      printf '%s\n' "error while recompressing $n.Z"
       res=1; continue
     fi
   else
@@ -107,7 +107,7 @@ for i do
       if cp -p "$n.Z" "$n.$$"; then
         :
       else
-        echo "cannot backup $n.Z"
+        printf '%s\n' "cannot backup $n.Z"
         res=1; continue
       fi
     fi
@@ -115,7 +115,7 @@ for i do
       :
     else
       test $check -eq 1 && mv "$n.$$" "$n.Z"
-      echo "error while uncompressing $n.Z"
+      printf '%s\n' "error while uncompressing $n.Z"
       res=1; continue
     fi
     if gzip $opt "$n"; then
@@ -123,10 +123,10 @@ for i do
     else
       if test $check -eq 1; then
         mv "$n.$$" "$n.Z" && rm -f "$n"
-        echo "error while recompressing $n"
+        printf '%s\n' "error while recompressing $n"
       else
         # compress $n  (might be dangerous if disk full)
-        echo "error while recompressing $n, left uncompressed"
+        printf '%s\n' "error while recompressing $n, left uncompressed"
       fi
       res=1; continue
     fi
@@ -139,7 +139,7 @@ for i do
     else
       mv "$n.$$" "$n.Z" && rm -f "$n$ext"
     fi
-    echo "$n.Z smaller than $n$ext -- unchanged"
+    printf '%s\n' "$n.Z smaller than $n$ext -- unchanged"
 
   elif test $check -eq 1; then
     if gzip -t "$n$ext" ; then
@@ -147,7 +147,7 @@ for i do
     else
       test $pipe -eq 0 && mv "$n.$$" "$n.Z"
       rm -f "$n$ext"
-      echo "error while testing $n$ext, $n.Z unchanged"
+      printf '%s\n' "error while testing $n$ext, $n.Z unchanged"
       res=1; continue
     fi
   elif test $pipe -eq 1; then