autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: testsuite 01


From: Eric Blake
Subject: Re: testsuite 01
Date: Tue, 6 May 2008 15:53:25 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> |> Subject: [PATCH] Improve behavior of 'tests/testsuite 01'.
> |>
> 
> Yes, adding the word 'variable' made more sense.  I committed the updated
> patch.
> 

I'm also committing this, after playing more with $(()).  It looks like pdksh, 
at least version 5.2.14, has a bug even when using 'set -o posix'.  And zsh 
behaves differently depending on whether it is in posix mode.  Bash and posh 
both met expectations without any extra effort.

>From 2811da8583226d60b8082852f8f6085e8c47bd3d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 6 May 2008 09:31:55 -0600
Subject: [PATCH] Document $(( )) pitfalls.

* doc/autoconf.texi (Shell Substitutions): Mention octal
vs. decimal.  Mention autotest's at_func_arith.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog         |    4 ++++
 doc/autoconf.texi |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 59a3119..c2d0f17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-05-06  Eric Blake  <address@hidden>
 
+       Document $(( )) pitfalls.
+       * doc/autoconf.texi (Shell Substitutions): Mention octal
+       vs. decimal.  Mention autotest's at_func_arith.
+
        Improve behavior of './testsuite 01'.
        * lib/autotest/general.m4 (AT_INIT) <at_func_validate_ranges>:
        Alter usage to eval its arguments, in order to normalize away
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index a5e880a..cd9a389 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -13203,6 +13203,44 @@ echo $(case x in x) echo hello;; esac)
 Arithmetic expansion is not portable as some shells (most
 notably Solaris 10 @command{/bin/sh}) don't support it.
 
+Among shells that do support @samp{$(( ))}, not all of them obey the
+Posix rule that octal and hexadecimal constants must be recognized:
+
address@hidden
+$ @kbd{bash -c 'echo $(( 010 + 0x10 ))'}
+24
+$ @kbd{zsh -c 'echo $(( 010 + 0x10 ))'}
+26
+$ @kbd{zsh -c 'emulate sh; echo $(( 010 + 0x10 ))'}
+24
+$ @kbd{pdksh -c 'echo $(( 010 + 0x10 ))'}
+pdksh:  010 + 0x10 : bad number `0x10'
+$ @kbd{pdksh -c 'echo $(( 010 ))'}
+10
address@hidden example
+
+When it is available, using arithmetic expansion provides a noticeable
+speedup in script execution; but testing for support requires
address@hidden to avoid syntax errors.  If shell function support has
+also been detected, then this construct can be used to assign @samp{foo}
+to an arithmetic result, provided all numeric arguments are provided in
+decimal and without a leading zero:
+
address@hidden
+if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then
+  eval 'func_arith ()
+  @{
+    func_arith_result=$(( $* ))
+  @}'
+else
+  at_func_arith ()
+  @{
+    func_arith_result=`expr "$@@"`
+  @}
+fi
+func_arith 1 + 1
+foo=$func_arith_result
address@hidden example
 
 
 @item ^
-- 
1.5.5.1








reply via email to

[Prev in Thread] Current Thread [Next in Thread]