dash: echo builtin interprets backslash escape sequences

Bug #259671 reported by Edward Crichton on 2008-08-20
56
This bug affects 4 people
Affects Status Importance Assigned to Milestone
dash (Debian)
Won't Fix
Unknown
dash (Ubuntu)
Undecided
Unassigned

Bug Description

In dash, backslashes are parsed within single quotes, contradicting POSIX and it's own man page.
POSIX: http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02

The following should print 2 backslashes:
echo '\\'

description: updated

Thank you for taking the time to report.
When I run your test script with bash (under karmic), I get the backslash as it should be. However when I run it with dash (the default /bin/sh since edgy, 6.10) the backslash does not get displayed.
Please run 'ls -l /bin/sh' so that we can decide if this is really a bash bug (dpkg -L containing /bin/sh does not mean that your /bin/sh is actually bash) or a dash bug.

Hi,

ls -l /bin/sh

/bin/sh -> dash

Aah. It's plugged into dash (as is the feisty version which is working).

Yann Leprince (sciyann) on 2010-01-06
Changed in bash:
status: New → Invalid
Yann Leprince (sciyann) wrote :

it appears that this is a bug in dash and not bash

affects: bash (Ubuntu) → dash (Ubuntu)
Yann Leprince (sciyann) on 2010-01-24
Changed in dash (Ubuntu):
status: New → Confirmed

There is a much simpler test: does
echo '\\'
print one backslash or 2?

The man page says:
   Single Quotes
     Enclosing characters in single quotes preserves the literal meaning of all the characters (except sin‐
     gle quotes, making it impossible to put single-quotes in a single-quoted string).

This bug should be SEVERE because it makes it practically impossible to write portable shell scripts.

description: updated
summary: - shell script parsing of strings when there is a square bracket. Missing
- backslashes
+ dash parses backslashes in single quotes
description: updated

The issue is not with the single quotes, but with dash's echo builtin. Apparently, the way they are compiled and configured by default on Ubuntu, dash's echo builtin interprets backslash escape sequences while bash's does not.

According to POSIX, this interpretation is permitted; with the XSI option (following traditional System V), it is required.

Practically, the echo utility can only be used portably if both backslashes and initial hyphens (which could be interpreted as options) are omitted. The printf utility is a good substitute.

I don't see much point in changing dash here.

Is this, then, the same as the bug I reported originally - that was later replaced by echo '\\':

BACKSLASH='\u'
SQUARE='\u[]'
echo $BACKSLASH
echo $SQUARE

gives
\u
u[] on ubuntu and \u[] everywhere else

So it is the echo command on Ubuntu dash only?
A work around would be to use printf in place of echo when using ubuntu? This would work reliably on other versions of sh?

> Date: Fri, 14 May 2010 22:55:17 +0000
> From: <email address hidden>
> To: <email address hidden>
> Subject: [Bug 259671] Re: dash parses backslashes in single quotes
>
> The issue is not with the single quotes, but with dash's echo builtin.
> Apparently, the way they are compiled and configured by default on
> Ubuntu, dash's echo builtin interprets backslash escape sequences while
> bash's does not.
>
> According to POSIX, this interpretation is permitted; with the XSI
> option (following traditional System V), it is required.
>
> Practically, the echo utility can only be used portably if both
> backslashes and initial hyphens (which could be interpreted as options)
> are omitted. The printf utility is a good substitute.
>
> I don't see much point in changing dash here.
>
> --
> dash parses backslashes in single quotes
> https://bugs.launchpad.net/bugs/259671
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Bourne Again Shell: Invalid
> Status in “dash” package in Ubuntu: Confirmed
> Status in “dash” package in Debian: New
>
> Bug description:
> In dash, backslashes are parsed within single quotes, contradicting POSIX and it's own man page.
> POSIX: http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02
>
> The following should print 2 backslashes:
> echo '\\'
>
>
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/bash/+bug/259671/+subscribe

_________________________________________________________________
http://clk.atdmt.com/UKM/go/197222280/direct/01/
Do you have a story that started on Hotmail? Tell us now

Jilles Tjoelker (jilles) wrote :

The Debian dash maintainer considers this a WONTFIX: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=550399

It seems unlikely that Ubuntu will want to override this.

summary: - dash parses backslashes in single quotes
+ dash: echo builtin interprets backslash escape sequences
Phillip Susi (psusi) on 2013-06-07
Changed in dash (Debian):
importance: Undecided → Unknown
status: New → Unknown
Changed in dash (Debian):
status: Unknown → Won't Fix
Richard Hansen (rhansen) wrote :

This is not a bug -- http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html says that echo should process the backslashes. It would be a bug if echo did not process the backslashes.

If you don't want backslashes processed, use printf:

    printf %s\\n '\\'

Changed in dash (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

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