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?
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.
Paolo