zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Paulo Diovani <paulo@diovani.com>
Cc: zsh-workers@zsh.org
Subject: Re: [Bug] comparisson operator `[[` not working as expected
Date: Mon, 20 Jun 2022 20:54:04 +0100	[thread overview]
Message-ID: <20220620195404.oamvev3ls6qnkpra@chazelas.org> (raw)
In-Reply-To: <CABdM12-XmzJNFECJto8hR0YROQOuq71p20Hb9jVAx6YNyF2RDg@mail.gmail.com>

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


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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 18:32 Paulo Diovani
2022-06-20 19:54 ` Stephane Chazelas [this message]
2022-06-20 20:07   ` Paulo Diovani
2022-06-20 20:30 ` Bart Schaefer
2022-06-21  0:47   ` Mikael Magnusson
2022-06-21  3:42     ` Bart Schaefer

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=20220620195404.oamvev3ls6qnkpra@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=paulo@diovani.com \
    --cc=zsh-workers@zsh.org \
    --subject='Re: [Bug] comparisson operator `[[` not working as expected' \
    /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

Code repositories for project(s) associated with this 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).