autoconf-patches
[Top][All Lists]
Advanced

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

[PATCHv2] m4sugar: factor away _AS_ECHO_PREPARE.


From: Gary V. Vaughan
Subject: [PATCHv2] m4sugar: factor away _AS_ECHO_PREPARE.
Date: Tue, 29 Jan 2013 09:24:47 +0700

Added NEWS entry, and updated texinfo documentation for echo.
Okay to push?

"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.text (Limitations of Shell Builtins): Document
preference for 'printf' over working around 'echo' bugs.
* NEWS: Updated.
Reported by Jim Meyering.
---
 NEWS                |  4 ++++
 doc/autoconf.texi   | 21 +++++++++----------
 lib/m4sugar/m4sh.m4 | 60 +++++++----------------------------------------------
 3 files changed, 21 insertions(+), 64 deletions(-)

diff --git a/NEWS b/NEWS
index a9b2226..2d76040 100644
--- 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"' unconditionally.
+
 ** Macros
 
 - New macro AC_C__GENERIC.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index bb83443..356c089 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -17494,12 +17494,16 @@ 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
address@hidden %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}.
+
+Where portability to obsolete environments, prior to the common
+availability of @command{printf}, is still a concern, and where you
+cannot be certain the arguments to @command{echo} do not contain
+backslashes or begin with a minus, it is suggested to use a
+here-document like this:
 
 @example
 cat <<EOF
@@ -17507,11 +17511,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 -----------------
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 25b4fe3..cd1718b 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -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
-- 
1.8.1




reply via email to

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