zsh-workers
 help / color / mirror / code / Atom feed
* [Bug] comparisson operator `[[` not working as expected
@ 2022-06-20 18:32 Paulo Diovani
  2022-06-20 19:54 ` Stephane Chazelas
  2022-06-20 20:30 ` Bart Schaefer
  0 siblings, 2 replies; 11+ messages in thread
From: Paulo Diovani @ 2022-06-20 18:32 UTC (permalink / raw)
  To: zsh-workers

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

Hello,

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

Expected

The result should be the same, in this case, with both [ ] and [[ ]].
Actual

[[ $(jobs -l | wc -l) -gt 0 ]] exit status is > 0 when there are jobs
running.
Version information

   - Zsh zsh 5.9 (x86_64-pc-linux-gnu)

Previous version, 5.8.1 was working as expected.
Distros

Tested in the following distros

   - Arch Linux (bare metal, docker)
   - Debian Sid (docker)

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

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2022-06-20 18:32 [Bug] comparisson operator `[[` not working as expected Paulo Diovani
@ 2022-06-20 19:54 ` Stephane Chazelas
  2022-06-20 20:07   ` Paulo Diovani
  2022-06-20 20:30 ` Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Stephane Chazelas @ 2022-06-20 19:54 UTC (permalink / raw)
  To: Paulo Diovani; +Cc: zsh-workers

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2022-06-20 19:54 ` Stephane Chazelas
@ 2022-06-20 20:07   ` Paulo Diovani
  0 siblings, 0 replies; 11+ messages in thread
From: Paulo Diovani @ 2022-06-20 20:07 UTC (permalink / raw)
  To: Paulo Diovani, zsh-workers

[-- 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 --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2022-06-20 18:32 [Bug] comparisson operator `[[` not working as expected Paulo Diovani
  2022-06-20 19:54 ` Stephane Chazelas
@ 2022-06-20 20:30 ` Bart Schaefer
  2022-06-21  0:47   ` Mikael Magnusson
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2022-06-20 20:30 UTC (permalink / raw)
  To: Paulo Diovani; +Cc: Zsh hackers list

On Mon, Jun 20, 2022 at 11:33 AM Paulo Diovani <paulo@diovani.com> wrote:
>
> In version 5.9 the [[ ]] operator is behaving unexpectedly for the following case:

Yep, this is a bug, introduced when a different crashing bug was
fixed.  It's an off-by-one error skipping the first job in the table.

The relevant ChangeLog entry for the crash bug is

2022-03-30  Peter Stephenson  <p.stephenson@samsung.com>

        * 49906 (Bart), 49911: Doc/Zsh/builtins.yo,
        Doc/Zsh/mod_parameter.yo, Src/exec.c, Src/jobs.c,
        Test/W03jobparameters.ztst: Fix querying jobs in subshell.

diff --git a/Src/jobs.c b/Src/jobs.c
index e0e453ed8..25ceb81c4 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -2402,7 +2402,7 @@ bin_fg(char *name, char **argv, Options ops, int func)
            int curmaxjob, ignorejob;
            if (unset(MONITOR) && oldmaxjob) {
                jobptr = oldjobtab;
-               curmaxjob = oldmaxjob ? oldmaxjob - 1 : 0;
+               curmaxjob = oldmaxjob ? oldmaxjob : 0;
                ignorejob = 0;
            } else {
                jobptr = jobtab;


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2022-06-20 20:30 ` Bart Schaefer
@ 2022-06-21  0:47   ` Mikael Magnusson
  2022-06-21  3:42     ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2022-06-21  0:47 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Paulo Diovani, Zsh hackers list

On 6/20/22, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mon, Jun 20, 2022 at 11:33 AM Paulo Diovani <paulo@diovani.com> wrote:
>>
>> In version 5.9 the [[ ]] operator is behaving unexpectedly for the
>> following case:
>
> Yep, this is a bug, introduced when a different crashing bug was
> fixed.  It's an off-by-one error skipping the first job in the table.
>
> The relevant ChangeLog entry for the crash bug is
>
> 2022-03-30  Peter Stephenson  <p.stephenson@samsung.com>
>
>         * 49906 (Bart), 49911: Doc/Zsh/builtins.yo,
>         Doc/Zsh/mod_parameter.yo, Src/exec.c, Src/jobs.c,
>         Test/W03jobparameters.ztst: Fix querying jobs in subshell.
>
> diff --git a/Src/jobs.c b/Src/jobs.c
> index e0e453ed8..25ceb81c4 100644
> --- a/Src/jobs.c
> +++ b/Src/jobs.c
> @@ -2402,7 +2402,7 @@ bin_fg(char *name, char **argv, Options ops, int
> func)
>             int curmaxjob, ignorejob;
>             if (unset(MONITOR) && oldmaxjob) {
>                 jobptr = oldjobtab;
> -               curmaxjob = oldmaxjob ? oldmaxjob - 1 : 0;
> +               curmaxjob = oldmaxjob ? oldmaxjob : 0;

Isn't this now just a very funny way to spell
  curmaxjob = oldmaxjob;
?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2022-06-21  0:47   ` Mikael Magnusson
@ 2022-06-21  3:42     ` Bart Schaefer
  2023-05-03 18:17       ` Paulo Diovani
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2022-06-21  3:42 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Paulo Diovani, Zsh hackers list

On Mon, Jun 20, 2022 at 5:47 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> > -               curmaxjob = oldmaxjob ? oldmaxjob - 1 : 0;
> > +               curmaxjob = oldmaxjob ? oldmaxjob : 0;
>
> Isn't this now just a very funny way to spell
>   curmaxjob = oldmaxjob;
> ?

Now that you mention it, yes.  Removing the -1 was just the closest
equivalent to the patch that created the problem.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2022-06-21  3:42     ` Bart Schaefer
@ 2023-05-03 18:17       ` Paulo Diovani
  2023-05-04  5:38         ` Mikael Magnusson
  0 siblings, 1 reply; 11+ messages in thread
From: Paulo Diovani @ 2023-05-03 18:17 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Mikael Magnusson, Zsh hackers list

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

Hello,
any news on this? I still have the issue on 5.9.

Thanks in advance.

On Tue, Jun 21, 2022 at 12:42 AM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Mon, Jun 20, 2022 at 5:47 PM Mikael Magnusson <mikachu@gmail.com>
> wrote:
> >
> > > -               curmaxjob = oldmaxjob ? oldmaxjob - 1 : 0;
> > > +               curmaxjob = oldmaxjob ? oldmaxjob : 0;
> >
> > Isn't this now just a very funny way to spell
> >   curmaxjob = oldmaxjob;
> > ?
>
> Now that you mention it, yes.  Removing the -1 was just the closest
> equivalent to the patch that created the problem.
>


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

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2023-05-03 18:17       ` Paulo Diovani
@ 2023-05-04  5:38         ` Mikael Magnusson
  2023-05-04 13:10           ` Paulo Diovani
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2023-05-04  5:38 UTC (permalink / raw)
  To: Paulo Diovani; +Cc: Bart Schaefer, Zsh hackers list

On 5/3/23, Paulo Diovani <paulo@diovani.com> wrote:
> Hello,
> any news on this? I still have the issue on 5.9.

That's not a great surprise as the 5.9 release pre-dates this thread
by about a month.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2023-05-04  5:38         ` Mikael Magnusson
@ 2023-05-04 13:10           ` Paulo Diovani
  2023-05-04 14:56             ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Paulo Diovani @ 2023-05-04 13:10 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Bart Schaefer, Zsh hackers list

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

Oh, sure, I know. It started on 5.9.
I was hoping a fix could come in a `5.9.1` or something. :)

On Thu, May 4, 2023 at 2:38 AM Mikael Magnusson <mikachu@gmail.com> wrote:

> On 5/3/23, Paulo Diovani <paulo@diovani.com> wrote:
> > Hello,
> > any news on this? I still have the issue on 5.9.
>
> That's not a great surprise as the 5.9 release pre-dates this thread
> by about a month.
>
> --
> Mikael Magnusson
>


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

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2023-05-04 13:10           ` Paulo Diovani
@ 2023-05-04 14:56             ` Bart Schaefer
  2023-05-04 17:42               ` Paulo Diovani
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2023-05-04 14:56 UTC (permalink / raw)
  To: Paulo Diovani; +Cc: Zsh hackers list

On Thu, May 4, 2023 at 6:10 AM Paulo Diovani <paulo@diovani.com> wrote:
>
> Oh, sure, I know. It started on 5.9.
> I was hoping a fix could come in a `5.9.1` or something. :)

This was included in commit cb59dfb and pushed to sourceforge.

diff --git a/ChangeLog b/ChangeLog
index 0cdd632f9..5220d2e83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2022-06-21  Bart Schaefer  <schaefer@zsh.org>

+       * 50379 (tweaked per 50380): Src/jobs.c: fix off-by-one
+       side-effect of workers/49906 that broke $(jobs -l)
+
        * 50368: Src/Modules/db_gdbm.c: adjust bitflags so local copies of
        variables cannot mess with database file contents


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Bug] comparisson operator `[[` not working as expected
  2023-05-04 14:56             ` Bart Schaefer
@ 2023-05-04 17:42               ` Paulo Diovani
  0 siblings, 0 replies; 11+ messages in thread
From: Paulo Diovani @ 2023-05-04 17:42 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

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

Awesome, thanks!

On Thu, May 4, 2023 at 11:56 AM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Thu, May 4, 2023 at 6:10 AM Paulo Diovani <paulo@diovani.com> wrote:
> >
> > Oh, sure, I know. It started on 5.9.
> > I was hoping a fix could come in a `5.9.1` or something. :)
>
> This was included in commit cb59dfb and pushed to sourceforge.
>
> diff --git a/ChangeLog b/ChangeLog
> index 0cdd632f9..5220d2e83 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,5 +1,8 @@
>  2022-06-21  Bart Schaefer  <schaefer@zsh.org>
>
> +       * 50379 (tweaked per 50380): Src/jobs.c: fix off-by-one
> +       side-effect of workers/49906 that broke $(jobs -l)
> +
>         * 50368: Src/Modules/db_gdbm.c: adjust bitflags so local copies of
>         variables cannot mess with database file contents
>


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

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-05-04 17:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20 18:32 [Bug] comparisson operator `[[` not working as expected Paulo Diovani
2022-06-20 19:54 ` Stephane Chazelas
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
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

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).