dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Marshall <john.marshall@sanger.ac.uk>
To: dash@vger.kernel.org
Subject: builtin read -r and backslash-char escape sequences
Date: Mon, 3 Aug 2015 17:37:20 +0100	[thread overview]
Message-ID: <EDC4419D-6669-4211-9005-8970B5499D9A@sanger.ac.uk> (raw)

Problems with one of my scripts appear to have been caused by dash's read -r translating escape sequences (like \t) whereas several other shells read them literally.  For example:

$ printf '%s' '\a\t\x' > backslashes 
$ dash -c 'read -r foo < backslashes; echo "$foo"' | cat -t
^G^I\x
$ bash -c 'read -r foo < backslashes; echo "$foo"' | cat -t
\a\t\x
$ ksh -c 'read -r foo < backslashes; echo "$foo"' | cat -t
\a\t\x

POSIX says of -r, "Do not treat a <backslash> character in any special way. Consider each <backslash> to be part of the input line" [1].  Translating them as escape sequences doesn't appear to be particularly compatible with this, but conceivably the translation is occurring at some other stage.

Is this the intended behaviour?

Thanks,

    John

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html#tag_20_109_04

-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 

             reply	other threads:[~2015-08-03 16:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 16:37 John Marshall [this message]
2015-08-03 17:03 ` builtin read -r and backslash-char escape sequences Eric Blake
2015-08-03 17:03 ` Harald van Dijk
2015-08-04  9:56   ` John Marshall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EDC4419D-6669-4211-9005-8970B5499D9A@sanger.ac.uk \
    --to=john.marshall@sanger.ac.uk \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).