dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Bosco <jbosco.gg@gmail.com>
Cc: dash@vger.kernel.org
Subject: Re: echo "\\1"?
Date: Thu, 27 Jul 2017 09:51:25 -0500	[thread overview]
Message-ID: <bf53bb8a-a967-023f-a83b-c0245702c1a4@redhat.com> (raw)
In-Reply-To: <CAC4gepcv49NcWqS-3jB50YrhJP8xYOhHyTFeL2TkifeJXRrQXA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1358 bytes --]

On 07/27/2017 09:44 AM, Bosco wrote:
> I don't have any problem, I only show you one case where I had to fix
> an script in order to work a compilation in dash.
> 
> I'm using dash because of simplicity, unfortunately I don't understand
> how things work.
> 
> I think the problem is of dash, I only want to report that dash fails
> at parse scape sequence.
> For instance, the command
> 
>   echo \\\\
> 
> prints
> 
>   \

Correct, per POSIX.  Incorrect, for portable code (since not all echo
implementations obey POSIX; many require to type

echo -e \\\\

to get single output, but -e is not POSIX).

> 
> I think it should print
> \\

Wrong per POSIX, but it matches what you get on bash if you don't turn
on 'shopt -s xpg_echo' and 'set -o posix' simultaneously (yes, bash has
two separate knobs that BOTH have to be on to get POSIX behavior).

> 
> I don't have to decided how dash should understand things because it
> isn't my project. I only advise of a bad behavior, of course from my
> point of view.

The bad behavior is not in dash, but in your non-portable use of echo
with a \ in the argument.  Use printf instead, if you want your script
to work in more than one shell.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2017-07-27 14:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 12:23 echo "\\1"? Bosco
2017-07-27 12:54 ` Eric Blake
2017-07-27 13:13   ` Bosco
2017-07-27 14:24     ` Eric Blake
2017-07-27 14:44       ` Bosco
2017-07-27 14:51         ` Eric Blake [this message]
2017-07-27 15:10           ` Bosco
2017-07-27 15:19             ` Eric Blake
2017-07-27 15:32             ` Bosco
2017-07-27 17:26       ` Harald van Dijk

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=bf53bb8a-a967-023f-a83b-c0245702c1a4@redhat.com \
    --to=eblake@redhat.com \
    --cc=dash@vger.kernel.org \
    --cc=jbosco.gg@gmail.com \
    /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).