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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2237 invoked from network); 7 Jan 2023 13:46:21 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Jan 2023 13:46:21 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1673099181; b=aK98tKV/C8bLqujWdgoyCadFHdHUezg5N6EFrAIlUXGprnAztVckxFXTNSWRPdrmLPbnkryQXg FAcoTW9zH5u9zymdszWawn0FntDnFw0Dmb5vWsfGXzpUYbI1PkI1eLhXM+tvhvYgEh1QAC+SNj kS8AbcIYyabd0cdJMewpTplH9B1JVlZIWYzAiOfoAvwLr3vMUHBhdbf2rqg/st7ZC+9BA7PXts p+hr9R17tRx5tNCn9ui9DBy9JapEWKB4Shh2j0SR14fpY8arlCVEGuwWR2aUNTXFDVF6G0VeAf QtbniMHG3XpUqn+GoFk0fiVzt/HrulnJS/wtmVE+I4rM8w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f48.google.com) smtp.remote-ip=209.85.217.48; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1673099181; bh=Qfddw4LaKc8Uolw0UjtaB2/XS6PCGrQeoCB8GQUkyi4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=VshyZCMFj/bDTGXzW52MEuctIebL/b17FUydkNmC4nq3NKPwEgspBtL1GLkK6rI5fhVRE1UGlz p3jwLqTmzRYL2rtKGqmzvWEFoBwCco3IIxAZtMrcCAozIqOSpjVKTxFXaa+Gwrd8fxcfN7+feo XFEK2CY2en/wH6r1S50bpL41/tX39u1PZzVGLZTPGJShq9EawqdhdNvIrbwUkZ6ENQWJU8Xdvh 8UEOFBR5RsbRdsJkEw6zhMj/jjsFniA9TXWPqO0CG0dXlCMHGM84Q/8e3cpUiTipRDqV9/gzr2 BoxPDu5PN8LzuMeE0e+LO0dYZgVZkxIBfoZmszQdNK+vPA==; 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:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=TwM2g8FWmERakIWs92dPF1ieb8KvRlAiNgH0Q6QN9Ug=; b=IRpJiixI7GaDlgQZowKVUrCpNE 7RAdy7idrKyVPS96vycusBvCXBTyBXU6kc8Zkw1wBVi/o1wYnFZaxz1fy8pC+XIB9oLoCdaPpU+sN dLDhQXlxNVd5pt8T5cwfV1Jd85h+vMgIPC9Mu2zN32LtRehQbQ8Jsie1+6hOr3Dm7fntKAenxWIRq vu9u5QSWm3DBKkF9GQ2h5BI5a80tRm9tMCWdj29Xg9nJEJFzg2ziq4zFFp+DNs4hqR1Mny1c0MhsT 5vvgZgVAcDa2e0/4NRVY1SAqYWnn+YLcPKSf5QRowytIjjRN7BqK9mY/a4W/KxDFTbdcjZA7iLE97 sEdVRGHw==; Received: by zero.zsh.org with local id 1pE9Wf-0007dj-Cq; Sat, 07 Jan 2023 13:46:21 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f48.google.com) smtp.remote-ip=209.85.217.48; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f48.google.com ([209.85.217.48]:46654) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pE9WN-0007Ih-8P; Sat, 07 Jan 2023 13:46:03 +0000 Received: by mail-vs1-f48.google.com with SMTP id x65so4196242vsb.13 for ; Sat, 07 Jan 2023 05:46:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TwM2g8FWmERakIWs92dPF1ieb8KvRlAiNgH0Q6QN9Ug=; b=VUrZcRb84bC5NeIlrirrsqucpbMaOj6WK9Kodt5HJ6GQ9Zdi1FsKd3oaLqsgf7jJak RZUbHjAgOJxj6CqiqSxt0bz6qRfDw8uUuT4zFpP/xxS4rZL11fDIAhwPL0OeE56pCZPo LrmKKpzLdoWuMAFkJT4jx/3n24kcXpZZy8MOzR4dQBhMa8lubWzGx0m5LZzqTMO3Pepm 4rU/A7qQ2WUbiJ2U5fRNzpXHydmq+M3B68QuEoBrx+X40poKeVXPS10/NgmRQOTdTrX/ XeQD2rnk5ejMchzplyVdiKkK9tbYloCndpDP7NBW0gsbffdHE81RJX64zKKwUGUirkT1 e+6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TwM2g8FWmERakIWs92dPF1ieb8KvRlAiNgH0Q6QN9Ug=; b=CfMre3pvAo3GNR4tI1OjhWsZWDlg4VdYTIwklc4vTjnmbiuB/iRongI+9YkNH/vcDw 3c4fSJU5V8KqFQpeYkBy/1gZd2i9jWu5mO0ZXYsAEqfduVjqUIiCUqjWMeljMFAr4AJy 658UYKFZkC6PP1L8M/+zuSiarLMqyTmWEZI7+QmjIfu2yMc5366KQdwaUDqCHr82R5cO p+Y8RILLzDZQRTbf6MOyp2jSVTUAYRALdNmhqOqcO3yDLQZ0m5YoUEj4BDAHxUC/lkLI tVc2MYn5bKes3Hf8izZolYr+ifbA5a2S0cEQJC+/ygr5L+uZJSClJpXqoWTCPXPhZ43p lNaw== X-Gm-Message-State: AFqh2ko0/JM2zHojTSpfliDxM394q/dY3wRomClU5VKuSrXpJOytxAE2 1dQACGx56hyzmZaSIA3QyVKfMAoWtWoqXuNs9Fs= X-Google-Smtp-Source: AMrXdXtY+irEdRtiqP9CsYFR62s7Z5/nobMog6w1f4wddeUnjJqsBea/OdCjy26P8FrmARJdQyt6xiqEh15XH0j9Biw= X-Received: by 2002:a05:6102:819:b0:3b5:f9a:7fae with SMTP id g25-20020a056102081900b003b50f9a7faemr7297096vsb.81.1673099161939; Sat, 07 Jan 2023 05:46:01 -0800 (PST) MIME-Version: 1.0 References: <361494476.8470860.1673025799682@mail.virginmedia.com> In-Reply-To: From: Philippe Altherr Date: Sat, 7 Jan 2023 14:45:50 +0100 Message-ID: Subject: Re: Subscript flag (i) not working correctly on empty strings? To: Bart Schaefer Cc: Peter Stephenson , Zsh hackers list Content-Type: multipart/alternative; boundary="00000000000038b2a405f1acc141" X-Seq: 51284 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: --00000000000038b2a405f1acc141 Content-Type: text/plain; charset="UTF-8" Thanks for the fix. For the record, I was trying to do something like this: separator_index=$input[(i):] > if [[ $separator_index -le $#input ]]; then > # Found separator > ... > fi Currently, an empty input incorrectly triggers the conditional code. To avoid it, an extra condition for that specific case is required, which is rather annoying. In the code above, an alternative would be to use (I) and test against 0, which works in all cases, but it feels wrong in my code where I also need the index of the *first* separator. Philippe On Fri, Jan 6, 2023 at 7:12 PM Bart Schaefer wrote: > On Fri, Jan 6, 2023 at 9:24 AM Peter Stephenson > wrote: > > > > > On 06/01/2023 16:01 Philippe Altherr > wrote: > > > > > > > s=; echo $s[(i)z]; > > > > > > > 0 > > > > > > Why is the last line 0 and not 1? > > > > Certainly looks plain wrong. > > None of the existing tests fail with this change. > > I thought there was a discussion about this at some point in the past > ... but it may have been limited to array cases. I have the feeling > we concluded that (i) and (I) should produce the same result on empty > string for purposes of boolean tests, but I can't find such a > conversation in the archives. I remain a little concerned that some > scripts are going to unexpectedly break, but can't point to anything, > and $anUnsetName[(i)z] returns nothing rather than 0, so it's probably > an unfounded worry. > --00000000000038b2a405f1acc141 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for the fix.

For the record, I w= as trying to do something like this:

separator_index=3D$input[(i):]
if [[ $s= eparator_index -le $#input ]]; then
=C2=A0 # Found separator
=C2=A0 .= ..
fi

Currently, an empty input incorrec= tly triggers the conditional code. To avoid it, an extra condition for that= specific case is required, which is rather annoying.

<= div>In the code above, an alternative would be to use (I) and test against = 0, which works in all cases, but it feels wrong in my code where I also nee= d the index of the first separator.

Philipp= e


On Fri, Jan 6, 2023 at 7:12 PM Bart Schaefer <schaefer@brasslantern.com> = wrote:
On Fri, J= an 6, 2023 at 9:24 AM Peter Stephenson
<p.w.st= ephenson@ntlworld.com> wrote:
>
> > On 06/01/2023 16:01 Philippe Altherr <philippe.altherr@gmail.com> = wrote:
> >
> > > s=3D; echo $s[(i)z];
> >
> > > 0
> >
> > Why is the last line 0 and not 1?
>
> Certainly looks plain wrong.
> None of the existing tests fail with this change.

I thought there was a discussion about this at some point in the past
... but it may have been limited to array cases.=C2=A0 I have the feeling we concluded that (i) and (I) should produce the same result on empty
string for purposes of boolean tests, but I can't find such a
conversation in the archives.=C2=A0 I remain a little concerned that some scripts are going to unexpectedly break, but can't point to anything, and $anUnsetName[(i)z] returns nothing rather than 0, so it's probably<= br> an unfounded worry.
--00000000000038b2a405f1acc141--