From: Benoit Sigoure Date: Fri, 2 Nov 2007 20:57:30 +0000 (+0100) Subject: Document a bug in GNU Bash with compound commands and redirections. X-Git-Tag: v2.62~171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c563e730bf9a57b49d8e03597a75a0cd117be72a;p=thirdparty%2Fautoconf.git 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 Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index a98e2103..325603f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-11-02 Benoit Sigoure + and Jim Meyering + and Andreas Schwab + and Eric Blake + + 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 Support m4 1.4.5 in testsuite. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 73077a03..2b205482 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{.} +@c -------------- @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{!} +@c -------------- @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 + +@item @command{@{...@}} +@c -------------------- +@prindex @command{@{...@}} +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 @{...@}, but also affects +other compound commands. + +@example +$ @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 +@end example + +The workaround is simple: prime bash with a simple command before any +compound command with redirection. + +@example +$ @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 +@end example + + @item @command{break} @c ------------------ @prindex @command{break}