From: Eric Blake Date: Fri, 11 Sep 2009 02:05:21 +0000 (-0600) Subject: Clarify portability pitfall of test. X-Git-Tag: v2.65~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98410813c9be734296603f7c582e30fb06165796;p=thirdparty%2Fautoconf.git Clarify portability pitfall of test. * doc/autoconf.texi (Limitations of Builtins) : Give more reasons why -a and -o are not portable. Reported by Reuben Thomas. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 80f560994..6e585f732 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-09-10 Eric Blake + + Clarify portability pitfall of test. + * doc/autoconf.texi (Limitations of Builtins) : Give more + reasons why -a and -o are not portable. + Reported by Reuben Thomas. + 2009-09-10 Ralf Wildenhues Document sed limitation with escaped metacharacters. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 82a9f2aa3..a43c6142f 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -16388,12 +16388,18 @@ that name in Autoconf code is asking for trouble since it is an M4 quote character. The @option{-a}, @option{-o}, @samp{(}, and @samp{)} operands are not -portable and should be avoided. Thus, portable uses of @command{test} -should never have more than four arguments, and scripts should use shell -constructs like @samp{&&} and @samp{||} instead. If you combine -@samp{&&} and @samp{||} in the same statement, keep in mind that they -have equal precedence, so it is often better to parenthesize even when -this is redundant. For example: +present in all implementations, and have been marked obsolete by Posix +2008. This is because there are inherent ambiguities in using them. +For example, @samp{test "$1" -a "$2"} looks like a binary operator to +check whether two strings are both non-empty, but if @samp{$1} is the +literal @samp{!}, then some implementations of @command{test} treat it +as a negation of the unary operator @option{-a}. + +Thus, portable uses of @command{test} should never have more than four +arguments, and scripts should use shell constructs like @samp{&&} and +@samp{||} instead. If you combine @samp{&&} and @samp{||} in the same +statement, keep in mind that they have equal precedence, so it is often +better to parenthesize even when this is redundant. For example: @smallexample # Not portable: