From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2655 invoked from network); 20 Jun 2022 20:09:50 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Jun 2022 20:09:50 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1655755790; b=oW22QDcUbVeOXwUFr1oX3i0FJ9gKB6SyWMw7t9laKj07Fooww/HuP9Nux3wpFBHLKwpujtOaUH MYqLKMDLntsrZhftyZ99ZW0jyubtG5TVCit3Aiy/JiwhWklwbx4GQv6yRdXlmyzfit5y5pqHSQ 8BxZjoCxPpeijK28RtFdRxatyQQfief8pghKn4FqKZGClptIyTgEjep7jyEArol8fbN76nPtOC bElVD0Zw4krr9dYYFMdPVBaDj1jG+DbtwOB2PIq/KbnHFQWz7L7z9kvPKMpjK8xX7amYdEnN8C lbsL+pDZ2TeY2msc2MsS5rX1xJx25+RU2nwSv+QSuVJYQQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f178.google.com) smtp.remote-ip=209.85.219.178; dkim=pass header.d=diovani-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=diovani.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1655755790; bh=X+i+n7ncLamwGDY1QDah3aFNdxILWHxIPEzDgSbqzyc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=c/kvknq84UL8L4l1m5iMELwvNxB8AM5Tnn20qWDR5JQ+FnVuULe4Axh+n3UPKtFp/t24jChixl TzyHHBo1eDaPn+hM2R7JvdrV03aqv4MfObMyxagXxu6Bx/zu2s64Hruqmy0XSN1tQbfsT678qp GAdo5gtdBc+ugQePFIHFbi/S/+gDaPaw4UgdNxA9SYG19yCCMLFQFEYBBazIqgKrnifM6N/tWG k5gs6FpVb51REkwcSfx3AmC9vSni6YapslXoOt/J7eunw33PmeYFGjAL83jySVBBJlizWYIGey l/5fGQOVK6OzZmAWSKfYQa1zebCunysaentrDLYu5wXBgA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=bSww/xq1N+xiCGOI2AUWohh9sQaPkkLWjja/K50WDd4=; b=UYPgIGlHo+DQuvRXchLg/RMCTw zhZtDxo8OeouJ7cNjR3YIhdzXFPO2SgCF9C5bBpzrNs5+5SuYXClB4Gy8seuGjPZNGo3/qiio4IDq 1qbbYJi1VYfs3HJFA0Q41YGRrBxFFKvsZ+M8mQuqoNNkT7qj/RMJke5APEp4zAc17ZGq8AucpAA/I SDKfkZlILUw2/otpqX9szMor7DLNNXAvmiXXmly6RKvGTO4vi80e3DN4FZs6nuR27uzBT8PgyxF6d kN1W1/EQkc2uKvWS6+JRGf9C514J8GhHqwsbjuhhBwlKKjF39xxIpcS+zhRf/KOSkbvpqp6h551cF a6m+jAMQ==; Received: from authenticated user by zero.zsh.org with local id 1o3NiY-000GcB-By; Mon, 20 Jun 2022 20:09:50 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f178.google.com) smtp.remote-ip=209.85.219.178; dkim=pass header.d=diovani-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=diovani.com; arc=none Received: from mail-yb1-f178.google.com ([209.85.219.178]:35340) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1o3NiI-000GHA-JS; Mon, 20 Jun 2022 20:09:35 +0000 Received: by mail-yb1-f178.google.com with SMTP id t1so20874487ybd.2 for ; Mon, 20 Jun 2022 13:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diovani-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=bSww/xq1N+xiCGOI2AUWohh9sQaPkkLWjja/K50WDd4=; b=GbOzFniMDuiRZEMIr1N2KgcC3tGaO/jUy3+gzGkKXM6VyUtlmObu8Z84UNVDU7fYop G+obSMZlOCVRHzkzBQbq+Umn5fWOUXaB7pR7CjKfE2DR9sXr8KEJm29/3dYUYCgpIVKW NXQVMQmGkL71VACWmPk4nlLLRVykaO6LE33UTwGU0PM4Ewmw6JMl/lryX5q8WsQKGcqN x2Bwfvn1/qutUwNvK2QSW54lLwY5jgJDN1Eas/MiM7Mht9MfMN4vfIxcKMRKbPYXdA1m vW9dTCmIldlj9Uk+ddeYS2Ns7tdbOqUZVOxKwJT1jof09uD9s0lEutRpV9vjUwyUcuzP 4JsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=bSww/xq1N+xiCGOI2AUWohh9sQaPkkLWjja/K50WDd4=; b=62/Z+8Q0WgIwhLTJDrxhEaUukDiNRPzvnuDUC2K6zy939L63byIPqcrokUG0XksP8q uCJDGbvzKqrUkClrVp2wmFWS0Pb1vzvudqI3lhalhJ1B7qkyg2U0lffZb6/1TqfxWqWI Gt/zKm1TJph01yT+uVCPc5RWq3ggR1BSuQhT1Q+KloZ7pI+FGk1w1Hj31mp4rIEJPddY aOiytrnj/3oo/70EoQocpfd9zIy6tRrg6lGYOh9LrD0SJ+QZjDbRfwi7aSthnHdH5E6o zYhJwjbbUoV6P522MPRYCHE2jh086vDrzTqpI7Qm/w3amFlFFMrt1bTGLDwkQ03yfpxu 6ziw== X-Gm-Message-State: AJIora+ri9JSDTjGEfMpvSGzYSTvEvOqWnHsQHyi+dmUjG0yLcwImnxb uX9OLJJBx0rI92Y0MmYt11NH2eB2TGf3N23rAbjnxg== X-Google-Smtp-Source: AGRyM1svsJUYu5TVzwQViM29TnvN/DiYRPfw/HEZRVz1rYudSztuKhMoc5UWmEWArHkoPrZcQiXEnrAnX0+WrThJSj0= X-Received: by 2002:a25:8187:0:b0:668:ce71:5f8f with SMTP id p7-20020a258187000000b00668ce715f8fmr15321959ybk.621.1655755772315; Mon, 20 Jun 2022 13:09:32 -0700 (PDT) MIME-Version: 1.0 References: <20220620195404.oamvev3ls6qnkpra@chazelas.org> In-Reply-To: <20220620195404.oamvev3ls6qnkpra@chazelas.org> From: Paulo Diovani Date: Mon, 20 Jun 2022 17:07:39 -0300 Message-ID: Subject: Re: [Bug] comparisson operator `[[` not working as expected To: Paulo Diovani , zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="000000000000a4de4d05e1e6ae4d" X-Seq: 50378 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --000000000000a4de4d05e1e6ae4d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=99t 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 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)]=3D... 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 > --=20 Paulo Diovani Gon=C3=A7alves, blog.diovani.com / @paulodiovani --000000000000a4de4d05e1e6ae4d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Thanks for the answer,

It could be an intentional chan= ge, but compared with the previous version or bash the behavior is quite di= fferent, and it can cause issues with several scripts.
Also, I didn=E2= =80=99t 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 scri= pts.

<= /div>
O= n Mon, Jun 20, 2022 at 4:54 PM Stephane Chazelas <stephane@chazelas.org> wrote:
2022-06-20 15:32:32 -0300, Paulo Di= ovani:
[...]
> 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 j= obs
> 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)]=3D... at least in my tests), a
better approach here would be to use:

if (( $#jobstates > 0 )); then
=C2=A0 echo jobs found
else
=C2=A0 echo no jobs
fi

--
Stephane


--
Paulo Diovani Gon=C3=A7alves,
blog.diovani.com / @paulodiovani


--000000000000a4de4d05e1e6ae4d--