zsh-users
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: lilydjwg <lilydjwg@gmail.com>, zsh-users@zsh.org
Subject: Re: test for newline in a variable--unexpected results sometimes
Date: Sun, 16 Sep 2018 15:53:54 -0500	[thread overview]
Message-ID: <DC89977C-A130-483E-A631-E7A2CD6AE7A0@dana.is> (raw)
In-Reply-To: <20180916204433.6k36inmuekgqp3a2@tarpaulin.shahaf.local2>

On 16 Sep 2018, at 15:44, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>In this context, «\n» does not mean a newline; it means either the letter 'n',
>or the two-character sequence «\n», but I don't remember which.

I was about to hit send on an answer to this but you addressed it. Here's a more
detailed explanation of this part (the effects of quoting):

* In an UNQUOTED string, all slash-escaped characters produce the literal
  version of the character being escaped:

  \\  ->  \
  \$  ->  $
  \1  ->  1
  \n  ->  n

* In a DOUBLE-QUOTED string, slash-escaped shell meta-characters produce the
  literal version of the character being escaped. Any other back-slash is left
  as-is:

  "\\"  ->  \
  "\$"  ->  $
  "\1"  ->  \1
  "\n"  ->  \n

* In a SINGLE-QUOTED string, all back-slashes are left as-is:

  '\\'  ->  \\
  '\$'  ->  \$
  '\1'  ->  \1
  '\n'  ->  \n

* In a DOLLAR-QUOTED string, escape sequences are interpreted according to the
  default behaviour of the print built-in, which supports various C-style
  sequences amongst other things. Sequences that aren't handled specifically are
  treated as they are in unquoted strings:

  $'\\'  ->  \
  $'\$'  ->  $
  $'\1'  ->  (ASCII character with octal code point 001)
  $'\n'  ->  (ASCII new-line)

This is mostly covered by the Shell Grammar section of the manual, though it's
not quite as explicit

dana


  reply	other threads:[~2018-09-16 20:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-16 17:27 lilydjwg
2018-09-16 20:44 ` Daniel Shahaf
2018-09-16 20:53   ` dana [this message]
2018-09-16 21:44     ` Dangling reference in zshroadmap(1) (was: Re: test for newline in a variable--unexpected results sometimes) Daniel Shahaf
2018-09-16 22:16       ` dana
2018-09-16 22:56         ` Daniel Shahaf
2018-09-17  3:20   ` test for newline in a variable--unexpected results sometimes lilydjwg

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=DC89977C-A130-483E-A631-E7A2CD6AE7A0@dana.is \
    --to=dana@dana.is \
    --cc=d.s@daniel.shahaf.name \
    --cc=lilydjwg@gmail.com \
    --cc=zsh-users@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).