On Ubuntu 9.04, with autoconf installed from repository: $ autoconf --version autoconf (GNU Autoconf) 2.63 [text deleted]
(NOTE: this problem is still present in 2.67) Here is the definition for AS_VAR_IF in m4sugar/m4sh.m4: ----------- snip here -------------- # AS_VAR_IF(VARIABLE, VALUE, IF-TRUE, IF-FALSE) # --------------------------------------------- # Implement a shell `if test $VARIABLE = VALUE; then-else'. # Polymorphic, and avoids sh expansion error upon interrupt or term signal. m4_define([AS_VAR_IF], [AS_LITERAL_IF([$1], [AS_IF([test "x$$1" = x""$2], [$3], [$4])], [as_val=AS_VAR_GET([$1]) AS_IF([test "x$as_val" = x""$2], [$3], [$4])])]) ----------- snip here -------------- The bug is located... [AS_IF([test "x$$1" = x""$2], [$3], [$4])], ...here ^^^^ AS_IF([test "x$as_val" = x""$2], [$3], [$4])])]) ...AND here ^^^^ It seems likely that x""$2 was meant to be "x$2". The bug in action: $ cat m4shtest.m4sh AS_INIT testvar="blah blah" indirecttestvar=testvar printf "Testing with literal variable name\n" AS_VAR_IF([testvar], [blah blah], [printf "compare OK\n"], [printf "compare failed\n"]) printf "Testing with indirect variable name\n" AS_VAR_IF([$indirecttestvar], [blah blah], [printf "compare OK\n"], [printf "compare failed\n"]) $ autom4te -l m4sh <m4shtest.m4sh >m4shtest.sh $ sh m4shtest.sh Testing with literal variable name test: 431: xblah: unexpected operator compare failed Testing with indirect variable name test: 440: xblah: unexpected operator compare failed $ cat -n m4shtest.sh |tail --lines +423 423 424 testvar="blah blah" 425 indirecttestvar=testvar 426 printf "Testing with literal variable name\n" 427 if test "x$testvar" = x""blah blah; then 428 printf "compare OK\n" 429 else 430 printf "compare failed\n" 431 fi 432 433 printf "Testing with indirect variable name\n" 434 as_val=`eval 'as_val=${'$indirecttestvar'} 435 $as_echo "$as_val"'` 436 if test "x$as_val" = x""blah blah; then 437 printf "compare OK\n" 438 else 439 printf "compare failed\n" 440 fi 441 $ A workaround would be to shell-quote the second argument to AS_VAR_IF, as in: AS_VAR_IF([testvar], ["blah blah"], [printf "compare OK\n"], [printf "compare But the documentation makes no mention that this is required. Furthermore, it seems unnecessary to inflict such a requirement. Instead, if the double quotes were rearranged as it seems they were originally meant... $ cat m4shtestfix.m4sh AS_INIT dnl 08/16/10 REC (14:48:20) Redefine AS_VAR_IF to fix bug: m4_define([AS_VAR_IF], [AS_LITERAL_IF([$1], [AS_IF([test "x$$1" = "x$2"], [$3], [$4])], [as_val=AS_VAR_GET([$1]) AS_IF([test "x$as_val" = "x$2"], [$3], [$4])])])dnl testvar="blah blah" indirecttestvar=testvar printf "Testing with literal variable name\n" AS_VAR_IF([testvar], [blah blah], [printf "compare OK\n"], [printf "compare failed\n"]) printf "Testing with indirect variable name\n" AS_VAR_IF([$indirecttestvar], [blah blah], [printf "compare OK\n"], [printf "compare failed\n"]) $ autom4te -l m4sh <m4shtestfix.m4sh >m4shtestfix.sh $ sh ./m4shtestfix.sh Testing with literal variable name compare OK Testing with indirect variable name compare OK $ cat -n m4shtestfix.sh |tail --lines +423 423 424 testvar="blah blah" 425 indirecttestvar=testvar 426 printf "Testing with literal variable name\n" 427 if test "x$testvar" = "xblah blah"; then 428 printf "compare OK\n" 429 else 430 printf "compare failed\n" 431 fi 432 433 printf "Testing with indirect variable name\n" 434 as_val=`eval 'as_val=${'$indirecttestvar'} 435 $as_echo "$as_val"'` 436 if test "x$as_val" = "xblah blah"; then 437 printf "compare OK\n" 438 else 439 printf "compare failed\n" 440 fi 441 $ ....Then all is well. Randall Cotton