Bug 604474 - bash builtin echo -E option hides and interprets "-E", "-n" and "-e" strings when they are first.
Summary: bash builtin echo -E option hides and interprets "-E", "-n" and "-e" strings ...
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: bash (Show other bugs)
(Show other bugs)
Version: 12
Hardware: All Linux
low
medium
Target Milestone: ---
Assignee: Roman Rakus
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-06-16 01:44 UTC by Paul Moore
Modified: 2014-01-13 00:12 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-06-16 14:31:17 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description Paul Moore 2010-06-16 01:44:00 UTC
Description of problem:

bash builtin echo -E option hides and interprets "-E", "-n" and "-e" strings when they are first.

Version-Release number of selected component (if applicable):
bash-4.0.35-3.fc12.x86_64
bash-3.0-19.3 (suse / Symantec Puredisk)
bash-3.1-16.1 (RHEL 5)

How reproducible:

Always.


Steps to Reproduce:
1. func() { echo -E "$@"; }
2. func "-E" "-n" "-e" "-hu\160"
or
1. echo -E '-E' '-n' '-e' '-hu\160'
  
Actual results:
'-hup[root@myserver ~]# '

Expected results:
'-E -n -e -hu\160
[root@myserver ~]# '

Additional info:
The bash man page states that the builtin echo:
"The  -E option disables the interpretation of these escape characters, even on systems where they are interpreted  by  default."

This is incorrect. They are interpreted and suppressed if one of the valid options is first in a separate string, quoted, double-quoted or not quoted.

The behaviour does not occur if the string contains more than just a single option, so echo -E '-E -n -e -hu\160' works as expected.

Comment 1 Roman Rakus 2010-06-16 10:52:37 UTC
Using the bash builtin echo I get what are you expecting.
Using the echo from coreutils I get your actual result.

Which echo are you using? What is `type echo' returning?

Comment 2 Paul Moore 2010-06-16 14:01:51 UTC
The problem of the "-E", "-n" "-e" characters not showing is the same for both the bash built-in "echo" and the coreutils "/bin/echo" on both Red Hat Enterprise Linux Server 5 and Fedora 12.

Red Hat Enterprise Linux 5 is interpreting the "-e" for both the bash built-in "echo" and the coreutils "/bin/echo", while Fedora 12 is not interpreting the "-e" for both the bash built-in "echo" and the coreutils "/bin/echo".

==============Results===============

[root@hmserver ~]# cat /etc/redhat-release ; rpm -qf $(which echo) $(which bash)
Red Hat Enterprise Linux Server release 5 (Tikanga)
coreutils-5.97-12.1.el5
bash-3.1-16.1
[root@hmserver ~]# which echo; which bash; echo -E '-E' '-n' '-e' '-hu\160'
/bin/echo
/bin/bash
-hup[root@hmserver ~]# 
[root@hmserver ~]# mv /bin/echo{,_}; echo -E '-E' '-n' '-e' '-hu\160'
-hup[root@hmserver ~]# mv /bin/echo{_,}
[root@hmserver ~]# 

-------------

[root@widebit ~]# cat /etc/redhat-release ; rpm -qf $(which echo) $(which bash)
Fedora release 12 (Constantine)
coreutils-7.6-11.fc12.x86_64
bash-4.0.35-3.fc12.x86_64
[root@widebit ~]# which echo; which bash; echo -E '-E' '-n' '-e' '-hu\160'
/bin/echo
/bin/bash
-hu\160[root@widebit ~]# mv /bin/echo{,_}; echo -E '-E' '-n' '-e' '-hu\160'
-hu\160[root@widebit ~]# mv /bin/echo{_,}

-------------

Comment 3 Paul Moore 2010-06-16 14:15:20 UTC
Sorry, I didn't properly read your request to use 'type echo'. - Repeated below with the same results.

I consider the primary problem to be that the "-E", "-n" "-e" characters are not showing when they are first on the line. This is the same for both
the bash built-in "echo" and the coreutils "/bin/echo" on both Red Hat
Enterprise Linux Server 5 and Fedora 12.

Red Hat Enterprise Linux 5 is interpreting the "-e" for both the bash built-in
"echo" and the coreutils "/bin/echo", while Fedora 12 is not interpreting the
"-e" for both the bash built-in "echo" and the coreutils "/bin/echo".

[root@hmserver ~]# cat /etc/redhat-release ; rpm -qf $(which echo) $(which bash)
Red Hat Enterprise Linux Server release 5 (Tikanga)
coreutils-5.97-12.1.el5
bash-3.1-16.1
[root@hmserver ~]# which echo; which bash; /bin/echo -E '-E' '-n' '-e' '-hu\160'
/bin/echo
/bin/bash
-hup[root@hmserver ~]# type echo; echo -E '-E' '-n' '-e' '-hu\160'
echo is a shell builtin
-hup[root@hmserver ~]# 


-----------------


[root@widebitfixed ~]# cat /etc/redhat-release ; rpm -qf $(which echo) $(which bash)
Fedora release 12 (Constantine)
coreutils-7.6-11.fc12.x86_64
bash-4.0.35-3.fc12.x86_64
[root@widebitfixed ~]# which echo; which bash; /bin/echo -E '-E' '-n' '-e' '-hu\160'
/bin/echo
/bin/bash
-hup[root@widebitfixed ~]# type echo; echo -E '-E' '-n' '-e' '-hu\160'
echo is a shell builtin
-hu\160[root@widebitfixed ~]#

Comment 4 Paul Moore 2010-06-16 14:16:56 UTC
This seems to also be a coreutils problem in at least coreutils-7.6-11.fc12.x86_64
and coreutils-5.97-12.1.el5.

Comment 5 Roman Rakus 2010-06-16 14:31:17 UTC
(In reply to comment #3)
> Sorry, I didn't properly read your request to use 'type echo'. - Repeated below
> with the same results.
> 
Please note the usage of `type' builtin. It is very usefull.

> I consider the primary problem to be that the "-E", "-n" "-e" characters are
> not showing when they are first on the line. This is the same for both
> the bash built-in "echo" and the coreutils "/bin/echo" on both Red Hat
> Enterprise Linux Server 5 and Fedora 12.
> 
> Red Hat Enterprise Linux 5 is interpreting the "-e" for both the bash built-in
> "echo" and the coreutils "/bin/echo", while Fedora 12 is not interpreting the
> "-e" for both the bash built-in "echo" and the coreutils "/bin/echo".
> 
> [root@hmserver ~]# cat /etc/redhat-release ; rpm -qf $(which echo) $(which
> bash)
> Red Hat Enterprise Linux Server release 5 (Tikanga)
> coreutils-5.97-12.1.el5
> bash-3.1-16.1
> [root@hmserver ~]# which echo; which bash; /bin/echo -E '-E' '-n' '-e'
> '-hu\160'
> /bin/echo
> /bin/bash
> -hup[root@hmserver ~]# type echo; echo -E '-E' '-n' '-e' '-hu\160'
> echo is a shell builtin
> -hup[root@hmserver ~]# 

> 
> 
> -----------------
> 
> 
> [root@widebitfixed ~]# cat /etc/redhat-release ; rpm -qf $(which echo) $(which
> bash)
> Fedora release 12 (Constantine)
> coreutils-7.6-11.fc12.x86_64
> bash-4.0.35-3.fc12.x86_64
> [root@widebitfixed ~]# which echo; which bash; /bin/echo -E '-E' '-n' '-e'
> '-hu\160'
> /bin/echo
> /bin/bash
> -hup[root@widebitfixed ~]# type echo; echo -E '-E' '-n' '-e' '-hu\160'
> echo is a shell builtin
> -hu\160[root@widebitfixed ~]#    

There is a problem elsewhere. On RHEL5 bash's echo interprets the escape
sequence in different way than F12 bash. Just try following example:
echo -e '\123'; echo -e '\0123'
on RHEL5 and on F12.

On RHEL5 there's no need for \0nnn format like on F12. This is the same like in
coreutils' echo.

Regarding multiple -E -e arguments - the last one is used.


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