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 2369 invoked from network); 6 Jan 2023 16:02:25 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 6 Jan 2023 16:02:25 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1673020946; b=pVvL0OGaMvvDQPoiOPTW879kU8Gb4uHoiJ8DiD3HoKk5VC6a7DZr+EORq2874SySk8v14JVLOf VVJrASMlo/UVXVx0wHhlONJC5hN2oHEr5SCec0PSYGQ5558Om+CGxwhZ0IQrMvQvQCW3bdEylt lGfD97vDIWm2SpEbfnpBd/Ui+DbeELKLpfgL29oCkIQOhHIvhLRxH6RHNjFRj4/83jIablFP9h PjeCXbOZq1AKtsroyTKvCQM6A5mVBvNqahzpGnk5u/BIYTAvBEgXXCWAhBmN/QpDA+1Wb6PNLi B+3/GeJkolWhQ61fmsuEn/P9BPRBZ9o3Q6CkNMXWVk/m0Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vk1-f171.google.com) smtp.remote-ip=209.85.221.171; 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=1673020946; bh=VMQglir0rOwGB6MaB8B8bGcxYfWvzci6h9xz3UsxDis=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=O4QYU3gc10GiQ1SipGUH2fvhxtylvXfNxBATuUS9NM6lfooN4TRQJbk0w8BGG9zIupAXS9D2MP MjnscQ99L9wmeu24wotykCD191kttako97nM93jXGETuxLkBbkwrSg4D5407ktPmmYG2T2bB9h DW4nIfROC8lbmM1sAQp9rXKMFVMBLv7x8Ajartvnq0pSJ1uNCzJABgI1oq95IfSbPQ7BVCmP5h 3w0Wqz2NFBhstWGYwQralAaBhk6Y+H6lCHSvyAQ6BTIf0MZixwXJLWfUtoQpRrDgFS/rKfBYxJ xlBHsFcvwqPXXGt+E+nglHaudCr/r/KMxkB2nfIufnDktA==; 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: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:In-Reply-To:References; bh=VMQglir0rOwGB6MaB8B8bGcxYfWvzci6h9xz3UsxDis=; b=TO/tYBnG1LcsORw+1SEIQWeXgw n9arWvasWy0AUTkijzf5cLKzKxK9YdSGlThVujOyxaMVceMAb7+EKHJd9bA9d8s7EB2JDukyW0s+s x6S1toHjziQrIuF4t4GSHsJUWZaE3UytZkhL5WiHBHXSDof4D2XZTV829ylyjpl15SHeS2xPyUxk9 Y6ISqwfdPAPDytxRrZ340hd3Yo0J995cgP/R3l3/1TDFGcKwr2u80sxf2Y+kPjhI1rMYYCLXTJR+O Z4H8+PCqlYUDNDD0HqZr8WfClxyNwlHR64V47Vx2YP7Y8UvNn4XdANQpU21DCRf2V+B/sj3A6X2gG Ifieo5CA==; Received: by zero.zsh.org with local id 1pDpAm-000LkB-Lm; Fri, 06 Jan 2023 16:02:24 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vk1-f171.google.com) smtp.remote-ip=209.85.221.171; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vk1-f171.google.com ([209.85.221.171]:39643) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pDpAF-000LQB-35; Fri, 06 Jan 2023 16:01:52 +0000 Received: by mail-vk1-f171.google.com with SMTP id t190so780392vkb.6 for ; Fri, 06 Jan 2023 08:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=VMQglir0rOwGB6MaB8B8bGcxYfWvzci6h9xz3UsxDis=; b=koc+G1oNfBH9ODlwjvvBOyNgI4M7fx9pzblQR0xPGc7dNJ+2FXgbRg8HOvOrKefz21 DMBNn2sC63sZlwIU5zZR7EQMW2cIF+HMMTzroBsH7BRLIIKpxiMUzbvxXHqGJ1qrQiXd XydkQifEoiVPcen7sttkwfPWlyrbxUWMhDB3g8UUOR7iigS0IHSlLdwot133AIMkhb69 mR9Q20SwP6cxAAPWj9dJ95cYbAeNm0jTuXdjhdCz7BtUVJYQ8tQN84Pv1ICStnPEm8jA 6jwltZiqqfssfwS2MBVnY4Y5koaPIEj0t6PTbvnlRyW4v/+/qTfSqw6DAyGD3DCtzGtb rZJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VMQglir0rOwGB6MaB8B8bGcxYfWvzci6h9xz3UsxDis=; b=4+yepdusYPgF/FgwzH17I/MWUEJlCFAWF9xYPPJi9F1wI6pUTPoAclDGS6xQDPv48h YsKd6WB/w7LRLaQVFFgynAiShbl2zrDRhHD1bpuQPhLTqyAUcRaTAzPixmkK/+YElDkw /Ya7GFVVE1ZLIhbXWtEXERblD50A7D/fy2N7iRGSwdXajl7N2g2s0CNCowhaXouqWPJg EPADDbuKBhNoaRx6khwaIpU69oVEHBrkj1fapgTVytEZ1bUSR9MmBHhszntbPOmBEtE4 3PR/lPJ8pWwWpg9k+5Id9INqYWrD52GvNgigFW8U5DGVpqHDn7jPfbucuK7vx6q8nIlH LOUw== X-Gm-Message-State: AFqh2kqJ1PZwNZCX2Tib2/XPk8vBl1oqSYEo/keyVg6iHWAAoSdcez9N XoT1VqgtJqkVknbjAF3F80eDn2+f0wJsXxNBTHWpqg4mKO0= X-Google-Smtp-Source: AMrXdXsyOoc5kO0unxy1+H4lX2uASjhIhUHlW/TVGRhYWBbeOKSufS6uBfuh1hhh+MswdYs2eguQfJ42EeK8VIy8xDE= X-Received: by 2002:a1f:3813:0:b0:3bc:e09a:3903 with SMTP id f19-20020a1f3813000000b003bce09a3903mr6236599vka.23.1673020908745; Fri, 06 Jan 2023 08:01:48 -0800 (PST) MIME-Version: 1.0 From: Philippe Altherr Date: Fri, 6 Jan 2023 17:01:37 +0100 Message-ID: Subject: Subscript flag (i) not working correctly on empty strings? To: Zsh hackers list Content-Type: multipart/alternative; boundary="000000000000f7ba0e05f19a88d0" X-Seq: 51277 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: --000000000000f7ba0e05f19a88d0 Content-Type: text/plain; charset="UTF-8" The following script s=aaa; echo $s[(i)z]; > s=aa; echo $s[(i)z]; > s=a; echo $s[(i)z]; s=; echo $s[(i)z]; prints this 4 > 3 > 2 > 0 Why is the last line 0 and not 1? The documentation of (i) and (r) states that if the pattern isn't found in the string, the length of the string plus 1 is returned. I can't find anything that would explain the 0. For arrays, (i) behaves as expected. The following script a=(a a a); echo $a[(i)z]; > a=(a a); echo $a[(i)z]; > a=(a); echo $a[(i)z]; a=(); echo $a[(i)z]; prints this 4 > 3 > 2 > 1 Is the empty string behavior a bug or an (undocumented?) feature? Philippe --000000000000f7ba0e05f19a88d0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
The following script

s=3Daaa; echo $s[(i)z];
s=3Daa; ec= ho $s[(i)z];
s=3Da; echo $s[(i)z];
s=3D; echo $s[(i)z];

prints this

4
3
2
0

Why is the = last line 0 and not 1? The documentation of (i) and (r) states that if the = pattern isn't found in the string, the length of the string plus 1 is r= eturned. I can't find anything that would explain the 0.

=
For arrays, (i) behaves as expected. The following script
<= div>
a=3D(a= a a); echo $a[(i)z];
a=3D(a a); echo $a[(i)z];
a=3D(a); echo $a[(i)z= ];
a=3D(= ); echo $a[(i)z];

prints this
4
3
2
1

Is the empty string behavi= or a bug or an (undocumented?) feature?

Philippe

--000000000000f7ba0e05f19a88d0--