Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
CONDITIONAL EXPRESSIONS, string == pattern
- X-seq: zsh-users 26805
- From: scowles@xxxxxxxx
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: CONDITIONAL EXPRESSIONS, string == pattern
- Date: Sat, 24 Jul 2021 19:14:28 -0700 (PDT)
- Archived-at: <https://zsh.org/users/26805>
- List-id: <zsh-users.zsh.org>
- Reply-to: scowles@xxxxxxxx
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author