-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Benoit Sigoure on 11/2/2007 2:57 PM:
>       * doc/autoconf.texi (Limitations of Builtins): Mention that GNU Bash
>       doesn't properly set $? when `{ ... } >/bad' fails.
>       (Use re-wording from Jim Meyering)

I'm proposing the following, which starts from your patch, but also
incorporates the additional issues with other compound commands discovered
by Jim, and the workaround discovered by Andreas (weird - a patch with
more contributors than lines describing the change :)

Any more edits before we check this in?

2007-11-02  Benoit Sigoure  <[EMAIL PROTECTED]>
        and Jim Meyering  <[EMAIL PROTECTED]>
        and Andreas Schwab <[EMAIL PROTECTED]>
        and Eric Blake  <[EMAIL PROTECTED]>

        Document a bug in GNU Bash with {...} blocks and redirections.
        * doc/autoconf.texi (Limitations of Builtins): Mention that GNU
        Bash doesn't properly set $? when `{ ... } >/bad' fails, and give
        workaround.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             [EMAIL PROTECTED]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHLJZy84KuGfSFAYARAiB+AKC+fCSyam8AaRoZxvH2oxw/811TcwCdGlu1
p7lPP3jbDHtj3Kj1+9MlrPM=
=ZVRV
-----END PGP SIGNATURE-----
>From 84aab2e342f234100bcba8eeaf2965fd002562bb Mon Sep 17 00:00:00 2001
From: Benoit Sigoure <[EMAIL PROTECTED]>
Date: Fri, 2 Nov 2007 21:57:30 +0100
Subject: [PATCH] Document a bug in GNU Bash with compound commands and 
redirections.

* doc/autoconf.texi (Limitations of Builtins): Mention that GNU
Bash doesn't properly set $? when `{ ... } >/bad' fails, and give
workaround.

Signed-off-by: Benoit Sigoure <[EMAIL PROTECTED]>
Signed-off-by: Eric Blake <[EMAIL PROTECTED]>
---
 ChangeLog         |   10 ++++++++++
 doc/autoconf.texi |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a98e210..325603f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-11-02  Benoit Sigoure  <[EMAIL PROTECTED]>
+       and Jim Meyering  <[EMAIL PROTECTED]>
+       and Andreas Schwab <[EMAIL PROTECTED]>
+       and Eric Blake  <[EMAIL PROTECTED]>
+
+       Document a bug in GNU Bash with compound commands and redirections.
+       * doc/autoconf.texi (Limitations of Builtins): Mention that GNU
+       Bash doesn't properly set $? when `{ ... } >/bad' fails, and give
+       workaround.
+
 2007-11-03  Eric Blake  <[EMAIL PROTECTED]>
 
        Support m4 1.4.5 in testsuite.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 73077a0..7d97a7f 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -13507,6 +13507,7 @@ the @samp{x} into account later in the pipe.
 
 @table @asis
 @item @command{.}
[EMAIL PROTECTED] --------------
 @prindex @command{.}
 Use @command{.} only with regular files (use @samp{test -f}).  Bash
 2.03, for instance, chokes on @samp{. /dev/null}.  Also, remember that
@@ -13515,6 +13516,7 @@ you want to use @command{.} on a file @file{foo} in the 
current
 directory, you must use @samp{. ./foo}.
 
 @item @command{!}
[EMAIL PROTECTED] --------------
 @prindex @command{!}
 The Unix version 7 shell did not support
 negating the exit status of commands with @command{!}, and this feature
@@ -13541,6 +13543,38 @@ More generally, one can always rewrite @samp{! 
@var{command}} as:
 if @var{command}; then (exit 1); else :; fi
 @end example
 
+
[EMAIL PROTECTED] @[EMAIL PROTECTED]@}}
[EMAIL PROTECTED] --------------------
[EMAIL PROTECTED] @[EMAIL PROTECTED]@}}
+As recently as GNU Bash 3.2, some shells do not properly set @samp{$?}
+when failing to write redirected output of any compound command other
+than a subshell group, when that compound command is the first thing
+executed.  This is most commonly observed with @[EMAIL PROTECTED], but affects
+other compound commands.
+
[EMAIL PROTECTED]
+$ @kbd{bash -c '@{ echo foo; @} >/bad; echo $?'}
+bash: line 1: /bad: Permission denied
+0
+$ @kbd{bash -c 'while :; do echo; done >/bad; echo $?'}
+bash: line 1: /bad: Permission denied
+0
[EMAIL PROTECTED] example
+
+The workaround is simple - prime bash with a simple command before any
+compound command with redirection.
+
[EMAIL PROTECTED]
+$ @kbd{bash -c ':; @{ echo foo; @} >/bad; echo $?'}
+bash: line 1: /bad: Permission denied
+1
+$ @kbd{bash -c ':; while :; do echo; done >/bad; echo $?'}
+bash: line 1: /bad: Permission denied
+1
[EMAIL PROTECTED] example
+
+
 @item @command{break}
 @c ------------------
 @prindex @command{break}
-- 
1.5.3.2

Reply via email to