Red Hat Bugzilla – Bug 591492
builtin echo -e does not handle \nnn octal escape unless its first digit is 0
Last modified: 2014-01-12 19:11:42 EST
Description of problem:
builtin echo -e does not handle \nnn octal escape unless its first digit is 0.
echo -e '\44' prints: \44
echo -e '\44' should print the character with code 44 octal, that is, '$'
Version-Release number of selected component (if applicable):
GNU bash, version 4.0.23(1)-release (x86_64-redhat-linux-gnu)
Older bash seems to be affected too:
GNU bash, version 3.2.39(1)-release (i686-pc-linux-gnu)
echo from GNU coreutils 7.2 treats '\44' as '$'.
both bash builtin printf and coreutils' printf treat '\44' as '$'.
Other Unixes' manpages seem to indicate that their echo's handle non-0-prefixed escape sequences too - see, say, http://ss64.com/bash/echo.html, http://swoolley.org/man.cgi/echo
So the bogus is echo from coreutils. See http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html
Also, bash's echo works as documented - see man page of echo builtin.
On bash 3.1.17(1) builtin echo does:
$ echo -e '\44'
GNU coreutils echo always supported \NNN format for octal character - it did not supported \0NNN until http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=97a6ce40ed4a34c9fb5eba5b50572f81bb839930 . This is documented in `info echo invocation` documentation. However - that's nonstandard thing, so bash builtin echo could choose to support only \0NNN octal format.
It was changed between 3.1 and 3.2 by http://git.savannah.gnu.org/cgit/bash.git/diff/builtins/echo.def?id=0628567a28f3510f506ae46cb9b24b73a6d2dc5d
for reference ...
(In reply to comment #1)
> So the bogus is echo from coreutils. See
> Also, bash's echo works as documented - see man page of echo builtin.
It's not like bash echo builtin does not support something on top of Open Group Base Specification. For example, that page doesn't document \e too, but \e works.
Nevertheless, bash works as documented and there's not any rule to handle \nnn in echo. Use printf instead - what is recommend...