read -r does not protect backslashes

Bug #880120 reported by Ian! D. Allen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dash (Ubuntu)
New
Undecided
Unassigned

Bug Description

Edit: This isn't a bug in "read" - it's the way dash's "echo" handles backslashes.

Both natty and oneiric dash fail to protect backslashes when using "read -r".

natty: dash 0.5.5.1-7.2ubuntu1
oneiric: dash 0.5.5.1-7.4ubuntu1

Example bug:

    $ echo '000\n999' | dash -c ' read -r f ; echo "$f" '
    000
    999

Other shells do it correctly:

    $ echo '000\n999' | bash -c ' read -r f ; echo "$f" '
    000\n999

    $ echo '000\n999' | static-sh -c ' read -r f ; echo "$f" '
    000\n999

This means you can't use "read" to read arbitrary lines of text.

ProblemType: Bug
DistroRelease: Ubuntu 11.04
Package: dash 0.5.5.1-7.2ubuntu1
ProcVersionSignature: Ubuntu 2.6.38-12.51-generic 2.6.38.8
Uname: Linux 2.6.38-12-generic x86_64
Architecture: amd64
Date: Sat Oct 22 18:28:32 2011
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release amd64 (20110427.1)
SourcePackage: dash
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Ian! D. Allen (idallen) wrote :
Revision history for this message
Jilles Tjoelker (jilles) wrote :

The backslash escape sequences are being processed by "echo", not "read". You can avoid this inconsistency by doing something like

printf "%s\n" '000\n999' | dash -c ' read -r f ; printf "%s\n" "$f" '

Revision history for this message
Ian! D. Allen (idallen) wrote :

Thanks Jilles - you are absolutely right. I had forgotten about versions of echo that process backslashes.
I see that one cannot turn off the backslash processing of the dash echo, which is why you need the printf.
Thanks!

description: updated
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.