[Top][All Lists]

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

Re: [PATCH 6/6] use print or printf or cat as $ECHO

From: Paolo Bonzini
Subject: Re: [PATCH 6/6] use print or printf or cat as $ECHO
Date: Mon, 10 Nov 2008 16:05:01 +0100
User-agent: Thunderbird (Macintosh/20080914)

> 'man print' on Solaris 10 shows that ksh also understands "print -R -" as
> a way to print "-" (but not "-n" or "--").  But you are right in realizing
> that "print -r --" seems to work nicely.

Yes, and "print -R" is broken on pdksh in that "print -R -n -n" should
print "-n" (it does on Darwin's ksh) but it does not.

> At any rate, that means we should probably teach m4sh to try "print -r --"
> as one of its options, prior to "printf %s\\n", during _AS_ECHO_PREPARE.

Maybe, also because in that case we have "print -r -n --" too.  But:

1) these tests do cost a few subshells (which can be as expensive as a
fork on bash, even if the executed command is a builtin).  In the
attached patch I conditionalized it on ${TMOUT} so that it is not
executed unless we're on ksh.

2) I'm not extremely fond of making the M4sh prolog even longer.  At one
point I even tried using only

  as_echo_body='eval expr "X$][1" : "X\\(.*\\)"'
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'

until we were past the detect-better-shell test, but that was too heavy
when the shell was not good enough.  To fix that you could rewrite
_AS_RUN to use here documents, and change the remaining uses of AS_ECHO
in error messages to cat.  Then you don't need at all anymore

commit 53d32c6d9a36d3087bf5ff8b92e491788b9f834a
Author: Paolo Bonzini <address@hidden>
Date:   Mon Nov 10 15:54:16 2008 +0100

    Use ksh `print -r' to implement $as_echo/$as_echo_n.
    * lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Try ksh `print -r'
    to implement $as_echo/$as_echo_n.

diff --git a/ChangeLog b/ChangeLog
index a2ca703..325130f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-11-10  Paolo Bonzini  <address@hidden>
+       Use ksh `print -r' to implement $as_echo/$as_echo_n.
+       * lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Try ksh `print -r'
+       to implement $as_echo/$as_echo_n.
 2008-11-09  Paolo Bonzini  <address@hidden>
        Balance parentheses in _AC_CACHE_DUMP.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index a506ef0..3648c1a 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -885,7 +885,10 @@ export as_nl
-if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+if test "X${TMOUT+set}" = Xset && (test "X`print -r -n -- -n; print -r -- 
-n$as_echo`" = "X-n-n$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -r -n --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
   as_echo='printf %s\n'
   as_echo_n='printf %s'

reply via email to

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