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,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 26703 invoked from network); 10 Mar 2022 12:49:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Mar 2022 12:49:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1646916555; b=fozaGiNDR+ZJ0j5rvjUTNEAU26HlOUMII+dAGdbw11C/q8B4J/hdjsjm66XOgPPe4QDKShShAt 7S5CBRomjtHkbqC3gN3EuxT/F0+NIC8PTzAabDWtA/jV8DXqF5SwzxJ1PdEnhOi8/uRUIx0sjg rBhRk4zlK2nbutZWkjSd9usWZkAs9y2W07OeIhY9ebP4QCpSdzNPn2SnPi5tlJKEB3QdHIxqxv dBvPj9kJsrR9HjZQYghx3hd50ur/JTKUG3hRL/rTtguIES1g+oR9t+X+EsUYCtjVrtrvK0gtvz 7Lqxh8cWDWuMyAL7RAafjCNM0iyHwCKVl8kxi9iEwUF9EQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-pl1-f174.google.com) smtp.remote-ip=209.85.214.174; 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=1646916555; bh=/KYS6hUE8KtCTP0EUMWfDqwcqze4+hiJ2/y4BurHAC8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:References: In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=CXkZi32x1umIRkhWjk8tvRdBaL53aPoEjAx2bQEpL1v9ETg79IWxUf9f2rtIFd4zyY/gu2bEMq 4OjxmRYX18MeDtbJSS1X4ygu1sFXa3WufRpXEu/JwWq4wb6ijWWmeC7i9L+eEnCfuMwAoXJPl7 zGQo1XnqcKk7qaTy0PZxUsGL4zssDB+/kREwW+edyDt8Thf9nJ3zXK3JiZwFvzcTVVv2HyrEmN Zj9RtaZRatEbpAwfve6ePo9TtCWa/SKjdxE5wSeLNDWMoWBUKAvQ3FKMPV/yxNnhLaYOCIui7M 9WQda1DNsySxCPhsZKUSYbPkNbzi/8I+4ZgAIXPS8Jf5Dg==; 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:References:In-Reply-To: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=hWzq5FoS3ixEFsWhYQ091AtO+Ith1QuJZYlzGiOk14Y=; b=J3UrSKWeYDf16KOluW0f38K2Ms lK3TLfr6dS60Zo//WEd+hYTfvRWEw2A9kCfABNKG/8tR04qrtqbs6RPVQvmrfUSZzXuPTUBTVpwbe JPj+nTpzjbWCNpWDnUqE7b0UbkS3WnuWZeXb7S0S4CZ7/2hHnJ9bHuiyRp9HwXiIU9htNDRLDqB/5 Jqpma1VP4lw6s5g2R//Ymoazw5woP1cAoCn25YiT2apI4fsLZ5IcxB6r9l3WJjf1LfqrkU15cQxMw 27vElFD2oMgcVfxdu9xzD9S/WNXbE1egh5V8FL7nYB7OuNsI9NPxI/jvJb30jmxJl1BiGl9DtANE7 nIPPSM+w==; Received: from authenticated user by zero.zsh.org with local id 1nSIEF-0009e6-EZ; Thu, 10 Mar 2022 12:49:15 +0000 Authentication-Results: zsh.org; iprev=pass (mail-pl1-f174.google.com) smtp.remote-ip=209.85.214.174; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-pl1-f174.google.com ([209.85.214.174]:39485) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nSIDz-0009IO-K2; Thu, 10 Mar 2022 12:48:59 +0000 Received: by mail-pl1-f174.google.com with SMTP id 9so4767609pll.6 for ; Thu, 10 Mar 2022 04:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=hWzq5FoS3ixEFsWhYQ091AtO+Ith1QuJZYlzGiOk14Y=; b=SMnqLFtU7BJzwUaosBvoNYU/woZrDH9YAGCyaILL9v9hlZ85v/zPDbUGiUDPqcEVyJ DpxHnmozv64Ex7UhDAfArF5X5U3S8WTY5TPnXfL/FoPV2xfysp1SIsuPbz9fjV6yuX3l LT6kOr86M0I4bx5ktyNhsYEOdLo/+w4Gq5bEjpShU6c01tZlk7RxyhzrYJVyadCpJ8IF O2LujtcC1GXmcELo6jw8aPftDL7I7kaWdhToA/pr37UfHnKrzInrmjDDfb18R75S/+7+ rOyeBhAnIKXO6z6nVzDPoLoVnLSILbWZZZ3yRdXC/e5H7YKwa971+Blz8CpJkVD7Vbrz zk9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=hWzq5FoS3ixEFsWhYQ091AtO+Ith1QuJZYlzGiOk14Y=; b=jBTBdHq1WMaWf+Srooew2hhF1pc0XWAIw0NT2m4ownkki+SgJT8WnQKyPMqK4/6GEW 6x+W8pWYRQQozkD21pfdazpHDkskUHFIwGXJl5+KYBWSI3iox0zLAnd4JaZtjXScBgNw KVK24Pm5B/TLDlCb4j7nAZdZ/jiwA6hMCBlBuFw/BmFuOYzty4Nb+aF61QsJK0T5IdjG nKQ0KBZeTz0Nj65D0Dl6avDhnMOE5+JKW/UrERlZZV2/P6aIDBONDeHIDZfANFVpzi7o W8S1IOkN1IlBbY6ylqbnnbO8cr1S6v4hMoo/oaNCo5kvJXVhzYgsvg4zrPX0fObRdv1N h0GQ== X-Gm-Message-State: AOAM533MUChu8LX7Jf91euHoJwW19W5VDEsN48dZFTrmT7gEzpux+aov NzMbinskfZ6GhrZMEdqOBo3XK0yOTTe+CyRHqfCoUZS9 X-Google-Smtp-Source: ABdhPJyGfvtt7GmXqg4gQxEW6GqgFOFOz79uo/qpPE3bjtulchV8mG4jHBC1/GNc1rUulhxkCeMhj9i+1ySs/j4+hhs= X-Received: by 2002:a17:90a:cce:b0:1bf:6387:30d9 with SMTP id 14-20020a17090a0cce00b001bf638730d9mr16056030pjt.196.1646916538206; Thu, 10 Mar 2022 04:48:58 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:6a10:466:0:0:0:0 with HTTP; Thu, 10 Mar 2022 04:48:57 -0800 (PST) In-Reply-To: <20220310075026.ovwlhxq24cmda5s3@chazelas.org> References: <20220310075026.ovwlhxq24cmda5s3@chazelas.org> From: Mikael Magnusson Date: Thu, 10 Mar 2022 13:48:57 +0100 Message-ID: Subject: Re: "${*:offset:length}" and ksh93/bash compatibility To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49821 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: On 3/10/22, Stephane Chazelas wrote: > Hello, > > From workers/28418 I understand the ${param:offset:length} was > introduced only for compatibility with bash (though the feature > was initially from ksh93) as zsh already had $param[first,last] > (long before bash had arrays or ksh93 even existed). > > Still, there's a difference with ksh/bash when > ${*:offset:length} (same for ${array[*]}) is quoted: > > $ zsh --emulate ksh -c 'printf "<%s>\n" ${*:1:2}' zsh foo bar baz > > > $ zsh --emulate ksh -c 'printf "<%s>\n" "${*:1:2}"' zsh foo bar baz > > > $ ksh -c 'printf "<%s>\n" ${*:1:2}' ksh foo bar baz > > > $ ksh -c 'printf "<%s>\n" "${*:1:2}"' ksh foo bar baz > > > $ bash -c 'printf "<%s>\n" ${*:1:2}' ksh foo bar baz > > > $ bash -c 'printf "<%s>\n" "${*:1:2}"' ksh foo bar baz > > > Should zsh align with bash/ksh there. If we do, it would probably look something like this (does not handle all cases), unless someone has a better idea... diff --git i/Src/subst.c w/Src/subst.c index 465fe970ff..a34ad5f571 100644 --- i/Src/subst.c +++ w/Src/subst.c @@ -2718,7 +2718,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } } /* See if this is a reference to the positional parameters. */ - if (v && v->pm && v->pm->gsu.a == &vararray_gsu && + if (v && v->pm && (char ***)v->pm->u.data == &pparams) horrible_offset_hack = 1; else @@ -3441,6 +3441,17 @@ colonsubscript: } if (offset < 0) offset = 0; + } else if (offset > 0 && horrible_offset_hack) { + offset--; + if (length_set && length > 0) { + char **elem; + int newlen = 0; + for (elem = aval; *elem && length; elem++) { + newlen += strlen(*elem) + 1; + length--; + } + length = newlen - 1; + } } given_offset = offset; MB_METACHARINIT(); -- Mikael Magnusson