Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: test for newline in a variable--unexpected results sometimes
- X-seq: zsh-users 23638
 
- From: dana <dana@xxxxxxx>
 
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
 
- Subject: Re: test for newline in a variable--unexpected results sometimes
 
- Date: Sun, 16 Sep 2018 15:53:54 -0500
 
- Cc: lilydjwg <lilydjwg@xxxxxxxxx>, zsh-users@xxxxxxx
 
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=dana-is.20150623.gappssmtp.com; s=20150623;        h=mime-version:subject:from:in-reply-to:date:cc         :content-transfer-encoding:message-id:references:to;        bh=U7z5sihEx15Bel2N8/8TI4kov+IpbRBDO3OV4jJ6Hl0=;        b=xcU5WwFewv8WepzyUBRBPuMLSlTHpKGeBVo4JJWWIfdkcRVx7E2LK1evix0lSNOKHk         cc1xcR/DFaoHm3LIN0+F7a24DC+DFxFJeGNLtYpOqESDsFl4r1kY+iCsXuiEXml2U8dy         eMQrX16bvu3PYJIqrzY6E/mGNxADc0QfWnVBbCxG4L/0/QTLG8tkRxjUycqI/dvT+2rk         apgZSpRaSCKweYR4i6WO6WRbmB3IgmqrTXIDr13gv4AwM6F5DUfMatFU4QIHCSGPCT45         j5psttpZ8giTqwTxE/EPguKqVT8ti7qkunYtCGASVqZBRb5ajkhF/FFCmIVZ48gdd8Qm         QbJw==
 
- In-reply-to: <20180916204433.6k36inmuekgqp3a2@tarpaulin.shahaf.local2>
 
- List-help: <mailto:zsh-users-help@zsh.org>
 
- List-id: Zsh Users List <zsh-users.zsh.org>
 
- List-post: <mailto:zsh-users@zsh.org>
 
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
 
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
 
- References: <20180916172716.GA27892@lilyforest.localdomain> <20180916204433.6k36inmuekgqp3a2@tarpaulin.shahaf.local2>
 
On 16 Sep 2018, at 15:44, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author