]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
m4sugar: factor away _AS_ECHO_PREPARE.
authorGary V. Vaughan <gary@gnu.org>
Mon, 28 Jan 2013 03:44:45 +0000 (10:44 +0700)
committerGary V. Vaughan <gary@gnu.org>
Tue, 29 Jan 2013 09:47:48 +0000 (16:47 +0700)
"printf '%s\n' ..." has been a fine replacement for plain "echo"
for at least 5 years (probably more like 10), even with most
museum-piece shells.
* lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Remove.
(_AS_SHELL_SANITIZE): Keep as_nl setting originally from
_AS_ECHO_PREPARE here where it more properly belongs.
(AS_ECHO, AS_ECHO_N): Use printf unconditionally.
* doc/autoconf.texi (Limitations of Shell Builtins): Document
preference for 'printf' over working around 'echo' bugs.
* NEWS: Updated.
Reported by Jim Meyering.

NEWS
doc/autoconf.texi
lib/m4sugar/m4sh.m4

diff --git a/NEWS b/NEWS
index 974d48d82a522fdac3a617bef761a754d5de7fdc..35e7b88b631928895b7fa87a86c1696714ba119b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ GNU Autoconf NEWS - User visible changes.
 ** Older version of automake and aclocal (< 1.8) are no longer supported
    by autoreconf.
 
+** Use of printf is now recommended instead of working around bugs in
+   echo.  Macros AS_ECHO and AS_ECHO_N now expand unconditionally to
+   "printf '%s\n'" and "printf %s".
+
 ** Macros
 
 - New macro AC_C__GENERIC.
index 2d6d8664188e37d00540cd3418aad1b79a18e849..c95d871c257f4e1eedb6427f6e1f3240421b10ef 100644 (file)
@@ -17522,12 +17522,14 @@ characters to @command{echo}.  For example, @samp{echo "$foo"} is safe
 only if you know that @var{foo}'s value cannot contain backslashes and
 cannot start with @samp{-}.
 
-If this may not be true, @command{printf} is in general safer and
-easier to use than @command{echo} and @command{echo -n}.  Thus, scripts
-where portability is not a major concern should use @command{printf
-'%s\n'} whenever @command{echo} could fail, and similarly use
-@command{printf %s} instead of @command{echo -n}. For portable shell
-scripts, instead, it is suggested to use a here-document like this:
+Normally, @command{printf} is safer and easier to use than @command{echo}
+and @command{echo -n}.  Thus, you should use @command{printf '%s\n'}
+instead of @command{echo}, and similarly use @command{printf %s} instead
+of @command{echo -n}.
+
+Older scripts, written before @command{printf} was portable,
+sometimes used a here-document as a safer alternative to @command{echo},
+like this:
 
 @example
 cat <<EOF
@@ -17535,11 +17537,6 @@ $foo
 EOF
 @end example
 
-Alternatively, M4sh provides @code{AS_ECHO} and @code{AS_ECHO_N} macros
-which choose between various portable implementations: @samp{echo}
-or @samp{print} where they work, @command{printf} if it is available,
-or else other creative tricks in order to work around the above problems.
-
 
 @item @command{eval}
 @c -----------------
index 25b4fe35678bf7eb75a419b2a12fac39a7b6d1a6..479c2d91ea330177c484617b5d2202acfb43930a 100644 (file)
@@ -453,7 +453,6 @@ m4_defun([_AS_SHELL_SANITIZE],
 [m4_text_box([M4sh Initialization.])
 
 AS_BOURNE_COMPATIBLE
-_AS_ECHO_PREPARE
 _AS_PATH_SEPARATOR_PREPARE
 
 # IFS
@@ -461,6 +460,9 @@ _AS_PATH_SEPARATOR_PREPARE
 # there to prevent editors from complaining about space-tab.
 # (If _AS_PATH_WALK were called with IFS unset, it would disable word
 # splitting by setting IFS to empty value.)
+as_nl='
+'
+export as_nl
 IFS=" ""       $as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
@@ -1023,63 +1025,15 @@ fi
 # Output WORD followed by a newline.  WORD must be a single shell word
 # (typically a quoted string).  The bytes of WORD are output as-is, even
 # if it starts with "-" or contains "\".
-m4_defun_init([AS_ECHO],
-[AS_REQUIRE([_$0_PREPARE])],
-[$as_echo $1])
+m4_defun([AS_ECHO],
+[printf '%s\n' $1])
 
 
 # AS_ECHO_N(WORD)
 # ---------------
 # Like AS_ECHO(WORD), except do not output the trailing newline.
-m4_defun_init([AS_ECHO_N],
-[AS_REQUIRE([_AS_ECHO_PREPARE])],
-[$as_echo_n $1])
-
-
-# _AS_ECHO_PREPARE
-# ----------------
-# Arrange for $as_echo 'FOO' to echo FOO without escape-interpretation;
-# and similarly for $as_echo_n, which omits the trailing newline.
-# 'FOO' is an optional single argument; a missing FOO is treated as empty.
-m4_defun([_AS_ECHO_PREPARE],
-[[as_nl='
-'
-export as_nl
-# Printing a long string crashes Solaris 7 /usr/bin/printf.
-as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
-as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
-as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
-# Prefer a ksh shell builtin over an external printf program on Solaris,
-# but without wasting forks for bash or zsh.
-if test -z "$BASH_VERSION$ZSH_VERSION" \
-    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
-  as_echo='print -r --'
-  as_echo_n='print -rn --'
-elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
-  as_echo='printf %s\n'
-  as_echo_n='printf %s'
-else
-  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
-    as_echo_body='eval /usr/ucb/echo -n "$][1$as_nl"'
-    as_echo_n='/usr/ucb/echo -n'
-  else
-    as_echo_body='eval expr "X$][1" : "X\\(.*\\)"'
-    as_echo_n_body='eval
-      arg=$][1;
-      case $arg in @%:@(
-      *"$as_nl"*)
-       expr "X$arg" : "X\\(.*\\)$as_nl";
-       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
-      esac;
-      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
-    '
-    export as_echo_n_body
-    as_echo_n='sh -c $as_echo_n_body as_echo'
-  fi
-  export as_echo_body
-  as_echo='sh -c $as_echo_body as_echo'
-fi
-]])# _AS_ECHO_PREPARE
+m4_defun([AS_ECHO_N],
+[printf %s $1])
 
 
 # AS_TEST_X