From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17949 invoked by alias); 5 Jul 2015 00:01:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35685 Received: (qmail 3533 invoked from network); 5 Jul 2015 00:01:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=9jYIn8x24KQgJEivfq9cJ8AyZfJ3kOWyDg2V59y4Vzc=; b=P9tMZcLLuOVgTf87iJzFoo+IZ+zoLdnYmHs2FFVXSVyUf+6t4jMVLAwtz52MWlsznK kkFndthY7Xpe5QPzBzp36RDYA2fm3y0qm9gpDbVcUae0tc6WVgm55+nl9NN8OCIQzNLm QK9t75SFsV4EjUpTrfoiLivYPAwhMnNBZV7p3N65Sa0zZOCjJpw9s1cFo/KxkmJuB7Nv UmyzIAB7KNfx8JRrhYD9bZutXwjezIh0jNVikfnuWHUajijP7T9fzTel2VMrWGXtKcWk 9r1mG+IEpNHSLupA8rfKPUPypSXbNPmmRli4tXiX7RAY7Ei67AYCKd1QjdtysZ0P+Odp zGow== X-Gm-Message-State: ALoCoQn2eZxyUu6K8Yw2FSRbd/J/xWxCOGaJQJ/Bt0Xd8MSjgC250bYQZVoJja5sfRKfCCrvCxcH X-Received: by 10.60.79.193 with SMTP id l1mr40285749oex.60.1436054511800; Sat, 04 Jul 2015 17:01:51 -0700 (PDT) From: Bart Schaefer Message-Id: <150704170147.ZM26204@torch.brasslantern.com> Date: Sat, 4 Jul 2015 17:01:47 -0700 In-Reply-To: Comments: In reply to Mikael Magnusson "nohistsubstpattern and :s//" (Jul 4, 3:22pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh workers Subject: Re: nohistsubstpattern and :s// MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Peter, this is yours from way back in workers/22934 -- any memory left from 2006? On Jul 4, 3:22pm, Mikael Magnusson wrote: } Subject: nohistsubstpattern and :s// } } % setopt histsubstpattern; a=(aaa bab cac) b=d; echo $a:s/a/${b}/ } daa bdb cdc Hmm ... hist_subst_pattern doesn't say anything about expansions in the replacement part of s/pat/rep/, so as far as I can tell this is contrary to the documentation. However, see below. } % setopt nohistsubstpattern; a=(aaa bab cac) b=d; echo $a:s/a/${b}/ } ${b}aa b${b}b cdc This has been like this for as long as the hist_subst_pattern option has existed, it appears. Random old builds I happen to have around show behavior matching the doc in 3.0.6 and 3.0.8 -- torch% echo $ZSH_VERSION 3.0.6-pre-5 torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/ ${b}aa b${b}b c${b}c torch% echo $ZSH_VERSION 3.0.8 torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/ ${b}aa b${b}b c${b}c -- but then after hist_subst_pattern is added in 4.3.3 -- torch% echo $ZSH_VERSION 4.3.17-test-2 torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/ ${b}aa b${b}b cdc -- and (still 4.3.17-test-2) -- torch% setopt histsubstpattern torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/ daa bdb cdc So this undocumented behaver of the replacement has also been around ever since the option was first implemented. The original test case in E01options.ztst even expects expansions in the replacement, so it seems to have been intentional, to allow references to $match in the event of backrefs in the pattern. This also changed the behavior for scalars when hist_subst_pattern is NOT set (note "g" added below): torch% echo $ZSH_VERSION 3.0.8 torch% a="aaa bab cac" b=d; echo $a:gs/a/${b}/ ${b}${b}${b} b${b}b c${b}c torch% echo $ZSH_VERSION 4.3.17-test-2 torch% a="aaa bab cac" b=d; echo $a:gs/a/${b}/ ddd bdb cdc So I suspect the same logic error (?) that changed this for scalars is also somehow affecting the last element of an array.