Bug 604474

Summary: bash builtin echo -E option hides and interprets "-E", "-n" and "-e" strings when they are first.
Product: [Fedora] Fedora Reporter: Paul Moore <pmoore>
Component: bashAssignee: Roman Rakus <rrakus>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 12CC: pmoore, rrakus, tsmetana
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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: --- Target Upstream Version:
Embargoed:

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.