zsh-workers
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-workers@zsh.org
Subject: [PATCH] Document echo \c behaviour
Date: Mon, 9 Jan 2017 15:32:09 -0500	[thread overview]
Message-ID: <20170109203209.GA13324@breadbox.private.spodhuis.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1845 bytes --]

Report on IRC asking about a behaviour difference between bash and zsh
led me down a rabbit hole.  While bash does the same thing as zsh when
given "echo -e", the behaviour was not documented in our man-pages and
was counter-intuitive.

    echo "foo\cbar" baz bat

Only the "foo" is output, with no final newline.

Commit logs show revision b77b51c in 2005 made this explicit, to "handle
\c escapes as per POSIX (truncating the output at the \c)".

SUSv4 XCU at <http://pubs.opengroup.org/onlinepubs/9699919799/> states:

 > \c
 > Suppress the <newline> that otherwise follows the final argument in
 > the output. All characters following the '\c' in the arguments shall
 > be ignored.

I think that this is worth documenting.  Patch tested with "make" in
Doc/ and results look fine.
---
 Doc/Zsh/builtins.yo | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 7b04d0648..4caefd5ba 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -453,7 +453,7 @@ tt(echo) recognizes the following escape sequences:
 startsitem()
 sitem(tt(\a))(bell character)
 sitem(tt(\b))(backspace)
-sitem(tt(\c))(suppress final newline)
+sitem(tt(\c))(suppress subsequent characters and final newline)
 sitem(tt(\e))(escape)
 sitem(tt(\f))(form feed)
 sitem(tt(\n))(linefeed (newline))
@@ -467,6 +467,9 @@ sitem(tt(\u)var(NNNN))(unicode character code in hexadecimal)
 sitem(tt(\U)var(NNNNNNNN))(unicode character code in hexadecimal)
 endsitem()
 
+POSIX requires for tt(echo) that "All characters following the tt(\c) in the
+arguments shall be ignored".
+
 pindex(BSD_ECHO, use of)
 The tt(-E) flag, or the tt(BSD_ECHO) option, can be used to disable
 these escape sequences.  In the latter case, tt(-e) flag can be used to
-- 
2.11.0


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2017-01-09 20:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-09 20:32 Phil Pennock [this message]
2017-01-10  3:52 ` Daniel Shahaf
2017-01-10  9:39   ` Phil Pennock
2017-01-10 16:05     ` Daniel Shahaf

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=20170109203209.GA13324@breadbox.private.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).