* What's wrong with this expression?
@ 2011-10-17 21:09 Daniel Serodio (lists)
2011-10-17 21:21 ` Dan Nelson
2011-10-17 21:21 ` Mikael Magnusson
0 siblings, 2 replies; 12+ messages in thread
From: Daniel Serodio (lists) @ 2011-10-17 21:09 UTC (permalink / raw)
To: zsh-users
I'm trying to troubleshoot a script that works with bash but fails with
zsh, and it uses the "regex match" operator. What's wrong with this
expression?
[[ "foo" ~= "x" ]] && echo true
Fails with "zsh: condition expected: ~="
Thanks in advance,
Daniel Serodio
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:09 What's wrong with this expression? Daniel Serodio (lists)
@ 2011-10-17 21:21 ` Dan Nelson
2011-10-17 21:21 ` Mikael Magnusson
1 sibling, 0 replies; 12+ messages in thread
From: Dan Nelson @ 2011-10-17 21:21 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: zsh-users
In the last episode (Oct 17), Daniel Serodio (lists) said:
> I'm trying to troubleshoot a script that works with bash but fails with
> zsh, and it uses the "regex match" operator. What's wrong with this
> expression?
>
> [[ "foo" ~= "x" ]] && echo true
>
> Fails with "zsh: condition expected: ~="
Try with =~ instead. Your line fails on bash as well:
$ [[ "foo" ~= "x" ]] && echo true
bash: conditional binary operator expected
bash: syntax error near `~='
--
Dan Nelson
dnelson@allantgroup.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:09 What's wrong with this expression? Daniel Serodio (lists)
2011-10-17 21:21 ` Dan Nelson
@ 2011-10-17 21:21 ` Mikael Magnusson
2011-10-17 21:27 ` Daniel Serodio (lists)
1 sibling, 1 reply; 12+ messages in thread
From: Mikael Magnusson @ 2011-10-17 21:21 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: zsh-users
On 17 October 2011 23:09, Daniel Serodio (lists)
<daniel.lists@mandic.com.br> wrote:
> I'm trying to troubleshoot a script that works with bash but fails with zsh,
> and it uses the "regex match" operator. What's wrong with this expression?
>
> [[ "foo" ~= "x" ]] && echo true
>
> Fails with "zsh: condition expected: ~="
You wrote ~= instead of =~
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:21 ` Mikael Magnusson
@ 2011-10-17 21:27 ` Daniel Serodio (lists)
2011-10-17 21:30 ` Mikael Magnusson
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Daniel Serodio (lists) @ 2011-10-17 21:27 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 613 bytes --]
Mikael Magnusson wrote:
> On 17 October 2011 23:09, Daniel Serodio (lists)
> <daniel.lists@mandic.com.br> wrote:
>> I'm trying to troubleshoot a script that works with bash but fails with zsh,
>> and it uses the "regex match" operator. What's wrong with this expression?
>>
>> [[ "foo" ~= "x" ]]&& echo true
>>
>> Fails with "zsh: condition expected: ~="
>
> You wrote ~= instead of =~
>
Ooops. Error copy'n'pasting. The actual line in the script that fails is:
if [[ ! "${PATH}" =~ $regex ]] ; then
where "regexp" is:
regex="^([^:]*:)*${rvm_bin_path}(:[^:]*)*$"
Thanks again,
Daniel Serodio
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:27 ` Daniel Serodio (lists)
@ 2011-10-17 21:30 ` Mikael Magnusson
2011-10-17 21:31 ` Daniel Serodio (lists)
2011-10-18 4:19 ` Phil Pennock
2011-10-18 6:28 ` Benjamin R. Haskell
2 siblings, 1 reply; 12+ messages in thread
From: Mikael Magnusson @ 2011-10-17 21:30 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: zsh-users
On 17 October 2011 23:27, Daniel Serodio (lists)
<daniel.lists@mandic.com.br> wrote:
> Mikael Magnusson wrote:
>
> On 17 October 2011 23:09, Daniel Serodio (lists)
> <daniel.lists@mandic.com.br> wrote:
>
> I'm trying to troubleshoot a script that works with bash but fails with zsh,
> and it uses the "regex match" operator. What's wrong with this expression?
>
> [[ "foo" ~= "x" ]] && echo true
>
> Fails with "zsh: condition expected: ~="
>
> You wrote ~= instead of =~
>
> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
>
> if [[ ! "${PATH}" =~ $regex ]] ; then
>
> where "regexp" is:
>
> regex="^([^:]*:)*${rvm_bin_path}(:[^:]*)*$"
Fails how?
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:30 ` Mikael Magnusson
@ 2011-10-17 21:31 ` Daniel Serodio (lists)
2011-10-17 21:43 ` Mikael Magnusson
0 siblings, 1 reply; 12+ messages in thread
From: Daniel Serodio (lists) @ 2011-10-17 21:31 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 789 bytes --]
Mikael Magnusson wrote:
> On 17 October 2011 23:27, Daniel Serodio (lists)
> <daniel.lists@mandic.com.br> wrote:
>> Mikael Magnusson wrote:
>>
>> On 17 October 2011 23:09, Daniel Serodio (lists)
>> <daniel.lists@mandic.com.br> wrote:
>>
>> I'm trying to troubleshoot a script that works with bash but fails with zsh,
>> and it uses the "regex match" operator. What's wrong with this expression?
>>
>> [[ "foo" ~= "x" ]]&& echo true
>>
>> Fails with "zsh: condition expected: ~="
>>
>> You wrote ~= instead of =~
>>
>> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
>>
>> if [[ ! "${PATH}" =~ $regex ]] ; then
>>
>> where "regexp" is:
>>
>> regex="^([^:]*:)*${rvm_bin_path}(:[^:]*)*$"
>
> Fails how?
>
Sorry. Fails with "condition expected: =~"
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:31 ` Daniel Serodio (lists)
@ 2011-10-17 21:43 ` Mikael Magnusson
2011-10-17 21:49 ` Daniel Serodio (lists)
0 siblings, 1 reply; 12+ messages in thread
From: Mikael Magnusson @ 2011-10-17 21:43 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: zsh-users
On 17 October 2011 23:31, Daniel Serodio (lists)
<daniel.lists@mandic.com.br> wrote:
> Mikael Magnusson wrote:
>
> On 17 October 2011 23:27, Daniel Serodio (lists)
> <daniel.lists@mandic.com.br> wrote:
>
> Mikael Magnusson wrote:
>
> On 17 October 2011 23:09, Daniel Serodio (lists)
> <daniel.lists@mandic.com.br> wrote:
>
> I'm trying to troubleshoot a script that works with bash but fails with zsh,
> and it uses the "regex match" operator. What's wrong with this expression?
>
> [[ "foo" ~= "x" ]] && echo true
>
> Fails with "zsh: condition expected: ~="
>
> You wrote ~= instead of =~
>
> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
>
> if [[ ! "${PATH}" =~ $regex ]] ; then
>
> where "regexp" is:
>
> regex="^([^:]*:)*${rvm_bin_path}(:[^:]*)*$"
>
> Fails how?
>
> Sorry. Fails with "condition expected: =~"
Maybe you don't have any regex module installed/loaded, does
-regex-match instead of =~ work?
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:43 ` Mikael Magnusson
@ 2011-10-17 21:49 ` Daniel Serodio (lists)
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Serodio (lists) @ 2011-10-17 21:49 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]
Mikael Magnusson wrote:
> On 17 October 2011 23:31, Daniel Serodio (lists)
> <daniel.lists@mandic.com.br> wrote:
>> Mikael Magnusson wrote:
>>
>> On 17 October 2011 23:27, Daniel Serodio (lists)
>> <daniel.lists@mandic.com.br> wrote:
>>
>> Mikael Magnusson wrote:
>>
>> On 17 October 2011 23:09, Daniel Serodio (lists)
>> <daniel.lists@mandic.com.br> wrote:
>>
>> I'm trying to troubleshoot a script that works with bash but fails with zsh,
>> and it uses the "regex match" operator. What's wrong with this expression?
>>
>> [[ "foo" ~= "x" ]]&& echo true
>>
>> Fails with "zsh: condition expected: ~="
>>
>> You wrote ~= instead of =~
>>
>> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
>>
>> if [[ ! "${PATH}" =~ $regex ]] ; then
>>
>> where "regexp" is:
>>
>> regex="^([^:]*:)*${rvm_bin_path}(:[^:]*)*$"
>>
>> Fails how?
>>
>> Sorry. Fails with "condition expected: =~"
>
> Maybe you don't have any regex module installed/loaded, does
> -regex-match instead of =~ work?
Hmmm, this seems to be the problem.
[[ "foo" -regex-match "x" ]] && echo x
fails with:
zsh: unrecognized condition: `foo'
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:27 ` Daniel Serodio (lists)
2011-10-17 21:30 ` Mikael Magnusson
@ 2011-10-18 4:19 ` Phil Pennock
2011-10-18 13:08 ` Daniel Serodio (lists)
2011-10-18 6:28 ` Benjamin R. Haskell
2 siblings, 1 reply; 12+ messages in thread
From: Phil Pennock @ 2011-10-18 4:19 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: Mikael Magnusson, zsh-users
On 2011-10-17 at 19:27 -0200, Daniel Serodio (lists) wrote:
> Mikael Magnusson wrote:
> > On 17 October 2011 23:09, Daniel Serodio (lists)
> >> [[ "foo" ~= "x" ]]&& echo true
> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
>
> if [[ ! "${PATH}" =~ $regex ]] ; then
See, this is why reporting the _actual_ code which causes an error
helps; or, if you want to simplify, at least test that the failure still
happens with the simplified version.
This was a bug, fixed on 2010-10-10 and the fix included in the release
of zsh 4.3.11. The current version of zsh is 4.3.12. Negated patterns
and tests combined with &&/|| failed prior to that when using the =~
operator.
If you are running 4.3.11 or newer, please state which version you're
using and preferably show the minimum needed to reproduce, starting from
"zsh -f".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-17 21:27 ` Daniel Serodio (lists)
2011-10-17 21:30 ` Mikael Magnusson
2011-10-18 4:19 ` Phil Pennock
@ 2011-10-18 6:28 ` Benjamin R. Haskell
2 siblings, 0 replies; 12+ messages in thread
From: Benjamin R. Haskell @ 2011-10-18 6:28 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: Mikael Magnusson, zsh-users
On Mon, 17 Oct 2011, Daniel Serodio (lists) wrote:
> Mikael Magnusson wrote:
>> On 17 October 2011 23:09, Daniel Serodio (lists) wrote:
>>> I'm trying to troubleshoot a script that works with bash but fails
>>> with zsh,
>>> [...]
>
> [...]
>
> if [[ ! "${PATH}" =~ $regex ]] ; then
>
> where "regexp" is:
>
> regex="^([^:]*:)*${rvm_bin_path}(:[^:]*)*$"
When first trying to set up rvm, it regularly segfaulted on me in
zsh-4.3.10. I initially narrowed the problem down to the __rvm_after_cd
function, and just gutted it by adding:
[[ -n "$ZSH_VERSION" ]] && return 0
as line 9 of ~/.rvm/scripts/cd
Then at least it sometimes worked. But, shortly thereafter, I just
updated Zsh to zsh-4.3.12, and haven't had problems since.
--
Best,
Ben
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-18 4:19 ` Phil Pennock
@ 2011-10-18 13:08 ` Daniel Serodio (lists)
2011-10-19 8:26 ` Phil Pennock
0 siblings, 1 reply; 12+ messages in thread
From: Daniel Serodio (lists) @ 2011-10-18 13:08 UTC (permalink / raw)
To: Daniel Serodio (lists), Mikael Magnusson, zsh-users
[-- Attachment #1: Type: text/plain, Size: 1097 bytes --]
Phil Pennock wrote:
> On 2011-10-17 at 19:27 -0200, Daniel Serodio (lists) wrote:
>> Mikael Magnusson wrote:
>>> On 17 October 2011 23:09, Daniel Serodio (lists)
>>>> [[ "foo" ~= "x" ]]&& echo true
>
>> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
>>
>> if [[ ! "${PATH}" =~ $regex ]] ; then
>
> See, this is why reporting the _actual_ code which causes an error
> helps; or, if you want to simplify, at least test that the failure still
> happens with the simplified version.
Mea culpa indeed. I tried to simplify the problem but ended up
complicating it.
> This was a bug, fixed on 2010-10-10 and the fix included in the release
> of zsh 4.3.11. The current version of zsh is 4.3.12. Negated patterns
> and tests combined with&&/|| failed prior to that when using the =~
> operator.
>
> If you are running 4.3.11 or newer, please state which version you're
> using and preferably show the minimum needed to reproduce, starting from
> "zsh -f".
Thanks a lot. This computer is running zsh 4.2.6, I'll try to have it
updated.
Regrards,
Daniel Serodio
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: What's wrong with this expression?
2011-10-18 13:08 ` Daniel Serodio (lists)
@ 2011-10-19 8:26 ` Phil Pennock
0 siblings, 0 replies; 12+ messages in thread
From: Phil Pennock @ 2011-10-19 8:26 UTC (permalink / raw)
To: Daniel Serodio (lists); +Cc: Mikael Magnusson, zsh-users
On 2011-10-18 at 11:08 -0200, Daniel Serodio (lists) wrote:
> >> Ooops. Error copy'n'pasting. The actual line in the script that fails is:
> >>
> >> if [[ ! "${PATH}" =~ $regex ]] ; then
> Thanks a lot. This computer is running zsh 4.2.6, I'll try to have it
> updated.
4.2.6 does not have the =~ operator.
=~ was added on 2007-05-01, when Peter applied my patch (I'm the one who
made the mistake which led to ! not working right). The first release
of zsh with this in was 4.3.5, released on or around 2008-02-01.
zsh 4.2.6 was released on or around 2005-12-03.
Try using -pcre-match instead -- zsh has had PCRE regex support for a
long time, it's only the =~ support and the zsh/regex for using the
system POSIX regexp libraries for extended regexps that were new with
4.3.5.
For those versions of zsh with =~ support, it does extended regexps by
default, unless you setopt REMATCH_PCRE. Anything which is a valid
extended regexp pattern is likely to be a valid PCRE regexp (but not
the other way around). "man pcrepattern" for more details.
if [[ ! "${PATH}" -pcre-match $regex ]]; then
# ...
fi
-Phil
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2011-10-19 8:26 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-17 21:09 What's wrong with this expression? Daniel Serodio (lists)
2011-10-17 21:21 ` Dan Nelson
2011-10-17 21:21 ` Mikael Magnusson
2011-10-17 21:27 ` Daniel Serodio (lists)
2011-10-17 21:30 ` Mikael Magnusson
2011-10-17 21:31 ` Daniel Serodio (lists)
2011-10-17 21:43 ` Mikael Magnusson
2011-10-17 21:49 ` Daniel Serodio (lists)
2011-10-18 4:19 ` Phil Pennock
2011-10-18 13:08 ` Daniel Serodio (lists)
2011-10-19 8:26 ` Phil Pennock
2011-10-18 6:28 ` Benjamin R. Haskell
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).