From: Gary V. Vaughan Date: Mon, 28 Jan 2013 03:44:45 +0000 (+0700) Subject: m4sugar: factor away _AS_ECHO_PREPARE. X-Git-Tag: v2.69b~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b59b6f8a79b8bf77e178ff4e5aa0ede433d39cf;p=thirdparty%2Fautoconf.git m4sugar: factor away _AS_ECHO_PREPARE. "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. --- diff --git a/NEWS b/NEWS index 974d48d8..35e7b88b 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". + ** Macros - New macro AC_C__GENERIC. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 2d6d8664..c95d871c 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -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 </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