zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: lilydjwg <lilydjwg@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: test for newline in a variable--unexpected results sometimes
Date: Sun, 16 Sep 2018 20:44:33 +0000	[thread overview]
Message-ID: <20180916204433.6k36inmuekgqp3a2@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20180916172716.GA27892@lilyforest.localdomain>

lilydjwg wrote on Mon, Sep 17, 2018 at 01:27:17 +0800:
> I get output from the skim tool. Then I test if it's multiline or not,
> but it fails mysteriously for some cases.
> 
> My test is like this:
> 
> [[ $cmd = *\n* ]]
> 

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.

> cmd2="cd \ncd /sys/class/leds"

Ditto..  If you try «xxd <<<$cmd2» you'll see the variable's value contains the
two-character sequence «\n».

What you're looking for is [[ $cmd == *$'\n'* ]].  «\n» is an escape sequence
in $''-strings, but not in other kinds of strings.

Cheers,

Daniel

  reply	other threads:[~2018-09-16 20:45 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 [this message]
2018-09-16 20:53   ` dana
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=20180916204433.6k36inmuekgqp3a2@tarpaulin.shahaf.local2 \
    --to=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).