zsh-users
 help / color / mirror / code / Atom feed
From: lilydjwg <lilydjwg@gmail.com>
To: zsh-users@zsh.org
Subject: test for newline in a variable--unexpected results sometimes
Date: Mon, 17 Sep 2018 01:27:17 +0800	[thread overview]
Message-ID: <20180916172716.GA27892@lilyforest.localdomain> (raw)

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* ]]

It doesn't work for the following data (I've echoed $cmd to the file):

> cat -E log
cd $
cd /sys/class/leds$

This fails too:

[[ $(<log) = *\n* ]]

But manually set the variable to the same text it works:

cmd2="cd \ncd /sys/class/leds"
[[ $cmd2 = *\n* ]] # this succeeded

Here's the hex dump of the file:

> xxd log
00000000: 6364 200a 6364 202f 7379 732f 636c 6173  cd .cd /sys/clas
00000010: 732f 6c65 6473 0a                        s/leds.

What's going on? I'm confused....


-- 
Best regards,
lilydjwg

             reply	other threads:[~2018-09-16 17:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-16 17:27 lilydjwg [this message]
2018-09-16 20:44 ` Daniel Shahaf
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=20180916172716.GA27892@lilyforest.localdomain \
    --to=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).