DASH Shell discussions
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: John Keeping <john@keeping.me.uk>, dash@vger.kernel.org
Subject: Re: [PATCH] [BUILTIN] Require leading '0' on octal escapes in echo
Date: Sat, 01 Nov 2014 18:58:47 +0100	[thread overview]
Message-ID: <54551F57.6090708@gigawatt.nl> (raw)
In-Reply-To: <53785239c041de620223d4a7beba523e1627b65a.1414861984.git.john@keeping.me.uk>

On 11/1/2014 6:14 PM, John Keeping wrote:
> printf(1) supports octal escape sequences in its format argument which
> are specified as (from POSIX):
>
> 	"\ddd", where ddd is a one, two, or three-digit octal number
>
> But the argument to the "%b" format specifier allows:
>
> 	"\0ddd", where ddd is a zero, one, two, or three-digit octal
> 	number
>
> which is similar to the wording for echo(1) (for XSI-conformant
> systems):
>
> 	\0num	Write an 8-bit value that is the zero, one, two, or
> 		three-digit octal number num.
>
> Because conv_escape() handles the first case, applying the second
> behaviour in conv_escape_str() must also catch the characters '1'-'7' so
> that they are not converted as octal numbers.

Your patch seems to have addressed the clear bugs of the patch in that 
other thread. Let me attempt to summarise the status:

- POSIX does not specify the behaviour of \1 in echo and in printf %b.

POSIX does not define the behaviour of escape sequences other than the 
ones it explicitly specifies. It does not require \1 to be handled as 
\\1. It allows it, but it allows the current dash behaviour too.

To quote from the echo specification: "if any of the operands contain a 
backslash ( '\' ) character, the results are implementation-defined", 
and the bit about XSI doesn't include an exception for \1.

To quote from the printf %b specification: "The interpretation of a 
backslash followed by any other sequence of characters is unspecified."

- bash treats \1 as \\1 in echo, but as \01 in printf %b.

- dash treats \1 as \01 in both echo and in printf %b.

- Your patch makes dash treat \1 as \01 in both echo and printf %b.

- The aim of the patch in the other thread was to make dash be more like 
bash.

If that is your aim too, if you want dash to behave like bash, in order 
to achieve that the code must no longer be shared between echo and 
printf %b. Here is a simple test you can run, where dash is without your 
patch, and ./src/dash is with your patch:

$ bash -c 'printf "%b" "\1"' | cat -v
^A
$ dash -c 'printf "%b" "\1"' | cat -v
^A
$ ./src/dash -c 'printf "%b" "\1"' | cat -v
\1

If that isn't your aim, if your aim is only to make dash meet POSIX 
requirements, then don't worry, it already does so.

Cheers,
Harald van Dijk

  reply	other threads:[~2014-11-01 17:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-01 17:14 [PATCH] [BUILTIN] Require leading '0' on octal escapes in echo John Keeping
2014-11-01 17:58 ` Harald van Dijk [this message]
2014-11-01 18:39   ` John Keeping

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=54551F57.6090708@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=dash@vger.kernel.org \
    --cc=john@keeping.me.uk \
    /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