zsh-users
 help / color / mirror / code / Atom feed
From: scowles@ckhb.org
To: Zsh Users <zsh-users@zsh.org>
Subject: CONDITIONAL EXPRESSIONS, string == pattern
Date: Sat, 24 Jul 2021 19:14:28 -0700 (PDT)	[thread overview]
Message-ID: <ae9325b1-1a8a-1384-3bd0-2286348843e@ckhb.org> (raw)

I would like to execute test on patterns that are dynamically generated and that 
change between invocations depending on other data.  When I generate a scalar 
parameter containing the pattern, construct the test statement, then invoke it, 
the test fails.  However, if I force an eval on the test statement, the test 
succeeds.  I do not understand zsh parsing in this case.  Could someone please 
let me know the mechanics I am missing?

thanks very much.

zsh version:  5.8, patch 460
platform:  x64, ubu 21.04, current patches

# test code begin:

unset vs vp r
local -a r

vs=' str1  a2'
vp=
vp+=[[:blank:]]##
vp+=str1
vp+=[[:blank:]]##
vp+=[[:alnum:]]
vp+=[[:alnum:]]

r=( ${(f)"$( eval echo 'test ${vs} == ${vp} && echo hi || echo lo' )"} )
echo ${r[-1]}

test ${vs} == ${vp} && echo hi || echo lo

# test code end.

first test output:   hi
second test output:  lo


             reply	other threads:[~2021-07-25  2:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-25  2:14 scowles [this message]
2021-07-25  3:30 ` Eric Cook
2021-07-25  3:48   ` Lawrence Velázquez

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=ae9325b1-1a8a-1384-3bd0-2286348843e@ckhb.org \
    --to=scowles@ckhb.org \
    --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).