From: Eric Blake <eblake@redhat.com>
To: Bosco <jbosco.gg@gmail.com>, dash@vger.kernel.org
Subject: Re: echo "\\1"?
Date: Thu, 27 Jul 2017 07:54:23 -0500 [thread overview]
Message-ID: <7253a908-22d2-03e3-5493-418ca31e5590@redhat.com> (raw)
In-Reply-To: <CAC4gepeczuKhmanuBqYybUTjvo6eNeZk6FyqHjOhx8n-qDfCSw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1439 bytes --]
On 07/27/2017 07:23 AM, Bosco wrote:
> According the man pages,
Which man pages? Echo is one of those programs that varies widely, and
you are MUCH better off using printf(1) instead of echo(1) if you are
trying to get newline suppression, trying to print something that might
begin with -, or trying to print something that might contain \.
> for echo command, "\\" should print '\'
> character, and \0digits should print the byte in octal base.
> But the command
>
> echo "\\1"
This is the same as
echo '\1'
which is NOT defined by POSIX as being a valid escape sequence that echo
must recognize.
(Did you mean to test
echo '\\1'
instead?)
Here's the POSIX list of required escape sequences:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
>
> outputs the byte 0x01 in hexadecimal (or 001 in octal).
> Is this a bad behavior or is intentional?
Arguably, since it is not required by POSIX, we don't have to do it. But
I also can't argue that POSIX forbids us to support \1 as an extension
(it says nothing about whether implementations can have additional
escape sequences). So I'll argue that it is intentional as a dash
extension. But if you can make dash smaller by getting rid of the
extension, that might be an acceptable patch.
--
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 --]
next prev parent reply other threads:[~2017-07-27 12:54 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 [this message]
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
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=7253a908-22d2-03e3-5493-418ca31e5590@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).