Problem with the echo command

Bug #78116 reported by nicolas66
This bug report is a duplicate of:  Bug #72167: dash "echo -e" echoes "-e". Edit Remove
6
Affects Status Importance Assigned to Milestone
dash (Ubuntu)
Confirmed
Wishlist
Unassigned

Bug Description

I have found a problem by using the echo command in a Makefile. The problem is simple :

1) I create a new file named 'Makefile'.
2) I fill it by typing these lines :

all:
        @echo -e "foo\nbar"

3) I obtain a strange output WITH the parameter -e :

-e foo
bar

Revision history for this message
Pappan (ppadman) wrote :

I am not sure what you mean by strange output:

-e option of echo recognizes escape sequences, so "\n" makes bar start in a new line.

Revision history for this message
Rich Johnson (nixternal) wrote :

The reason this happens is because Ubuntu now uses a non-bash /bin/sh by default known as dash. In order to get it to work the way you want, you need to relink /bin/sh to /bin/bash instead of /bin/dash.

Rich Johnson (nixternal)
Changed in dash:
importance: Medium → Wishlist
Revision history for this message
David Fox (david-fox) wrote :

This is a real problem in makefiles, causing some builds to fail:

% bash -c 'echo "hello\n"'
hello\n
% dash -c 'echo "hello\n"'
hello

%

I would suggest that dash is not ready for prime time as a replacement for bash.

Revision history for this message
Micah Cowan (micahcowan) wrote :

Note that the interpretation of "\n" is not at all consistent between different shell varieties (although, IMO, interpreting them by default is broken. It certainly breaks POSIX, but then, nearly all echo implementations do).

The literal interpretation of -e, however, is mandated by POSIX, and would not be a bug.

Revision history for this message
Micah Cowan (micahcowan) wrote :

It might be worth opening a separate bug on the fact that dash breaks POSIX (which it purports to support) by interpreting "\n" specially. The text of your last comment would serve well as a description.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.