Bug 591492 - builtin echo -e does not handle \nnn octal escape unless its first digit is 0
builtin echo -e does not handle \nnn octal escape unless its first digit is 0
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: bash (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: Roman Rakus
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-05-12 08:10 EDT by Denys Vlasenko
Modified: 2014-01-12 19:11 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-07-01 08:50:37 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Denys Vlasenko 2010-05-12 08:10:34 EDT
Description of problem:

builtin echo -e does not handle \nnn octal escape unless its first digit is 0.
Example:
echo -e '\44' prints: \44


Expected results:
echo -e '\44' should print the character with code 44 octal, that is, '$'


Version-Release number of selected component (if applicable):
bash --version
GNU bash, version 4.0.23(1)-release (x86_64-redhat-linux-gnu)
Older bash seems to be affected too:
bash --version
GNU bash, version 3.2.39(1)-release (i686-pc-linux-gnu)


Additional info:
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
Comment 1 Roman Rakus 2010-05-12 09:20:35 EDT
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.
Comment 2 Ondrej Vasik 2010-05-12 10:46:53 EDT
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 ...
Comment 3 Denys Vlasenko 2010-05-12 11:08:56 EDT
(In reply to comment #1)
> 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.    

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.
Comment 4 Roman Rakus 2010-07-01 08:50:37 EDT
Nevertheless, bash works as documented and there's not any rule to handle \nnn in echo. Use printf instead - what is recommend...

Note You need to log in before you can comment on or make changes to this bug.