zsh-workers
 help / color / mirror / code / Atom feed
From: Paulo Diovani <paulo@diovani.com>
To: Paulo Diovani <paulo@diovani.com>, zsh-workers@zsh.org
Subject: Re: [Bug] comparisson operator `[[` not working as expected
Date: Mon, 20 Jun 2022 17:07:39 -0300	[thread overview]
Message-ID: <CABdM128i6cdBKSDMC6NaeE8WppBD+2NNePSu7nK76DnpbBCxrQ@mail.gmail.com> (raw)
In-Reply-To: <20220620195404.oamvev3ls6qnkpra@chazelas.org>

[-- Attachment #1: Type: text/plain, Size: 1370 bytes --]

Thanks for the answer,

It could be an intentional change, but compared with the previous version
or bash the behavior is quite different, and it can cause issues with
several scripts.
Also, I didn’t find the change in behavior listed in the changelog for 5.9,
so it may be a new bug or regression.

I just use that line to define my PROMPT and I can easily update, but I
worry that the change could be more troublesome for other packages or
automation scripts.

On Mon, Jun 20, 2022 at 4:54 PM Stephane Chazelas <stephane@chazelas.org>
wrote:

> 2022-06-20 15:32:32 -0300, Paulo Diovani:
> [...]
> > In version 5.9 the [[ ]] operator is behaving unexpectedly for the
> > following case:
> >
> > $ watch ls &
> > $ [ $(jobs -l | wc -l) -gt 0 ] && echo jobs found || echo no jobs
> > jobs found
> > $ [[ $(jobs -l | wc -l) -gt 0 ]] && echo jobs found || echo no jobs
> > no jobs
> [...]
>
> While I agree that looks like a bug (the output of jobs seems to
> be empty when the command substitution is expanded inside
> [[...]] or ((...)) or a[$(jobs)]=... at least in my tests), a
> better approach here would be to use:
>
> if (( $#jobstates > 0 )); then
>   echo jobs found
> else
>   echo no jobs
> fi
>
> --
> Stephane
>


-- 
Paulo Diovani Gonçalves,
blog.diovani.com / @paulodiovani <http://twitter.com/paulodiovani>

[-- Attachment #2: Type: text/html, Size: 3378 bytes --]

  reply	other threads:[~2022-06-20 20:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 18:32 Paulo Diovani
2022-06-20 19:54 ` Stephane Chazelas
2022-06-20 20:07   ` Paulo Diovani [this message]
2022-06-20 20:30 ` Bart Schaefer
2022-06-21  0:47   ` Mikael Magnusson
2022-06-21  3:42     ` Bart Schaefer
2023-05-03 18:17       ` Paulo Diovani
2023-05-04  5:38         ` Mikael Magnusson
2023-05-04 13:10           ` Paulo Diovani
2023-05-04 14:56             ` Bart Schaefer
2023-05-04 17:42               ` Paulo Diovani

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=CABdM128i6cdBKSDMC6NaeE8WppBD+2NNePSu7nK76DnpbBCxrQ@mail.gmail.com \
    --to=paulo@diovani.com \
    --cc=zsh-workers@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).