On Sun, Nov 12, 2017 at 11:53 PM, Paul Eggert <egg...@cs.ucla.edu> wrote:
> Bruno Haible wrote:
>>
>> ! # Produce output and exit with code 1 if there is a write error.
>> ! # Use 'exec echo', not plain 'echo', because the 'echo' built-in in
>> ! # HP-UX /bin/sh does not check for write errors.
>> ! # Use '|| exit 1', because the 'echo' program on HP-UX exits with
>> ! # code 2 in case of a write error, but we want code 1.
>> ! --help)    (exec echo "$usage") || exit 1; exit 0;;
>> ! --version) (exec echo "$version") || exit 1; exit 0;;
>
>
> Thanks for the patch. I don't think we need worry about the first problem,
> since gzip assumes a working POSIX shell and the first problem is a failure
> to conform to POSIX. We can ask builders on HP-UX to work around the problem
> by configuring with SHELL=/bin/bash, or with some other POSIX-compatible
> shell.
>
> The second problem is indeed a bug in gzip, since it shouldn't assume that
> echo exits with status 1 on failure (it could be some other positive
> status).
>
> I notice that some gzip scripts already fix that bug, and some other scripts
> do not fix it. Also, while we're at it, scripts should use printf instead of
> echo if the strings might contain backslash (at least in theory; admittedly
> a backslash in a version number would be pretty weird). I looked for these
> problems in all the scripts and installed the attached to fix what I found.

Nice. Thanks, Paul.
I've pushed this additional fix:
From 801fd9110048e817fea291317116e4085a6081b0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Mon, 13 Nov 2017 07:20:05 -0800
Subject: [PATCH] zless, znew: exit 1 upon --help or --version write failure

* zless.in: Exit 1 upon --help or --version write error.
* znew.in: Likewise.
---
 zless.in | 4 ++--
 znew.in  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/zless.in b/zless.in
index 5c20d82..e4da708 100644
--- 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)    printf '%s\n' "$usage"  ; exit;;
---version) printf '%s\n' "$version"; exit;;
+--help)      printf '%s\n' "$usage"   || exit 1; exit;;
+--version)   printf '%s\n' "$version" || exit 1; exit;;
 esac

 if test "${LESSMETACHARS+set}" != set; then
diff --git a/znew.in b/znew.in
index 5c98256..48475e9 100644
--- a/znew.in
+++ b/znew.in
@@ -60,8 +60,8 @@ ext=.gz
 for arg
 do
   case "$arg" in
-  --help)      printf '%s\n' "$usage"  ; exit;;
-  --version)   printf '%s\n' "$version"; exit;;
+  --help)      printf '%s\n' "$usage"   || exit 1; exit;;
+  --version)   printf '%s\n' "$version" || exit 1; exit;;
   -*)     opt="$opt $arg"; shift;;
    *)     break;;
   esac
-- 
2.14.1.729.g59c0ea183

Reply via email to