Hi Paolo. On Wed, 29 Jul 2009, Paolo Bonzini wrote:
> > New applications which are not aiming at portability should use > > `printf' instead of `echo'. M4sh provides the `AS_ECHO' and > > `AS_ECHO_N' macros, which choose between `echo -n' on > > implementations where that works, `printf' if it is available, or > > other creative tricks in order to work around the above problems. > > > > Shouldn't the entry for printf mention this portability shortcoming of > > printf as well? The entry for printf says printf is not always a shell builtin, but the above text implies printf might not be available at all. Is the latter a concern for printf? I've assumed so in the patch below, so that needs to be fixed if not. > > Also, I find the first sentence above confusing. Why is printf > > recommended if not for portability? > > Because it is true echo is not safe (it may eat the beginning of your output), > but it is a mess to find a way to print that is also fast (i.e. possible it is > a builtin). It may be print -r, echo --, echo -n, whatever. If you just use > printf %s\n you are done, but you lose a tiny bit of portability. If you > strive for portability at all costs, and do not use M4sh, you can look at > other solutions. Thanks for the explanation. So "ease of use" or "safety" would be a good summary of printf's advantage over echo? My problem with the current documentation is that it doesn't make this clear. This section is about portability. After reading several paragraphs about echo's lack of portability, I arrive at a paragraph that describes an alternative, printf, a command I've so far not read about. Given this context, I expect the advantage of printf to be portability, but I'm told that portability specifically isn't the advantage, and I'm never told what is. The first time I read this, I thought the "not" in "not aiming a portability" was a typo. I feel the following patch clarifies the explanation a bit. >From b4f8e75ad864a1479e741f065673ea0439764081 Mon Sep 17 00:00:00 2001 From: Joel E. Denny <jde...@clemson.edu> Date: Thu, 30 Jul 2009 08:40:51 -0400 Subject: [PATCH] In manual, clarify comparison of echo, printf, and AS_ECHO*. Discussed starting at <http://lists.gnu.org/archive/html/bug-autoconf/2009-07/msg00025.html>. * doc/autoconf.texi (Limitations of Builtins): In echo's entry, give a reason why printf is better than echo. In printf's entry, mention printf's lack of availability, and cross-reference echo's entry. --- ChangeLog | 10 ++++++++++ doc/autoconf.texi | 17 +++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61bda1a..b420d8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-07-30 Joel E. Denny <jde...@clemson.edu> + + In manual, clarify comparison of echo, printf, and AS_ECHO*. + Discussed starting at + <http://lists.gnu.org/archive/html/bug-autoconf/2009-07/msg00025.html>. + * doc/autoconf.texi (Limitations of Builtins): In echo's entry, + give a reason why printf is better than echo. In printf's + entry, mention printf's lack of availability, and + cross-reference echo's entry. + 2009-07-29 Ralf Wildenhues <ralf.wildenh...@gmx.de> testsuite: avoid bogus hostname match from inner test logs. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 4f046c0..021f280 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -15836,12 +15836,14 @@ $foo EOF @end example -New applications which are not aiming at portability should use -...@command{printf} instead of @command{echo}. M4sh provides the -...@code{as_echo} and @code{AS_ECHO_N} macros, which choose between -...@samp{echo -n} on implementations where that works, @command{printf} if -it is available, or other creative tricks in order to work around the -above problems. +While @command{printf} is not available on all systems, it is safer and +easier to use than @command{echo}. +Thus, new applications which are not aiming at portability should use +...@command{printf} instead of @command{echo}. +When portability is important, M4sh provides the @code{AS_ECHO} and +...@code{as_echo_n} macros, which choose between @samp{echo -n} on +implementations where that works, @command{printf} if it is available, +or other creative tricks in order to work around the above problems. @item @command{eval} @@ -16148,6 +16150,9 @@ for an @command{echo} that does not interpret @samp{\} or leading @samp{-}. With Solaris @command{ksh}, it is possible to use @code{print -r --} for this role instead. +...@command{printf} is not available on all systems. +For a discussion of M4sh's portable alternative to both @command{printf} +and @command{echo}, @xref{echo, , Limitations of Shell Builtins}. @item @command{pwd} @c ---------------- -- 1.5.4.3