From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 9B3D721167 for ; Wed, 27 Mar 2024 23:22:58 +0100 (CET) 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:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=kPN0bYAdDWhPi871G+7NIKoegH1bfXKkCF63vIei6x4=; b=Yyil3bHIyYTzkcn4BygYxFSd6G UMjGd2aOFXR1w5DKa5MYnbiVS1g3kmRVYO9jgIIcBpa0EIexc9ZsohCCtdHd5YxoPNg5SJPehLU/4 39bMSBqozHjbD9Hc2woEkykPG2bFHUwtd2XAJu0WPUqALLVIKV6+9mQybohM3meAm+hyywQQR358N +t/vIOZIbLyBBStryhtDsC9cHChw5J7Eg/fCkcP1tgKzlAkP91kvMEV1nO5w4g7XEvRmGNCy+8szG GlJ0CR2IO3CC1jfwoYSphyLC1eLOtR9jpJxrIIUDSG1ION/NfTcVUi/cHhttKD9YXmSoUmnETzooT ilqMmmkA==; Received: by zero.zsh.org with local id 1rpbfb-000FQH-Mb; Wed, 27 Mar 2024 22:22:55 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rpbfN-000F8n-FQ; Wed, 27 Mar 2024 22:22:41 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1rpbfM-00000000BB1-1OCg; Wed, 27 Mar 2024 23:22:40 +0100 cc: Zsh hackers list In-reply-to: From: Oliver Kiddle References: To: Bart Schaefer Subject: Re: Nofork ${{var}...} edge cases MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <42965.1711578160.1@hydra> Date: Wed, 27 Mar 2024 23:22:40 +0100 Message-ID: <42966-1711578160.323146@w_2U.aZv1.yyMw> X-Seq: 52833 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: Bart Schaefer wrote: > Just seeking opinions: > > Should ${{} true} (empty variable name) result in "bad substitution"? Given that ${} just outputs nothing, the current behaviour of also outputting nothing is entirely consistent. That is just a zshism, however: ksh: syntax error: `}' unexpected bash: ${}: bad substitution /bin/sh: ${}: Bad substitution I prefer zsh's behaviour here - ignoring the error - but would guess the reason for it may be related to the support for nested substitutions. And while uses of ${} alone are rare, variants such as ${:-xx} are useful. Your patch doesn't allow a substitution inside the {}, however so nested substitutions are not a reason here. > Otherwise it's all side-effects, because nothing will be substituted. > The prior ${|| true} form was a parse error. > > Should ${{var}} be a "bad substitution", or print a warning about an > empty command? Otherwise it just substitutes $var. Again, I think I prefer the approach of doing as the user says even if it doesn't appear to make much sense - so just substitude $var. If that produces an error, what about ${{var}$=CMD} where CMD is unset. > What about ${{var};} or ${{var}{}} etc.? And there's probably a further half-dozen ways we've not thought of. > Or we could declare ${{REPLY}...} as NOT synonymous with ${|...} and > localize REPLY only in the latter of those. That might actually make > more sense. That definitely makes most sense to me. > Among the reasons I listed for not doing this, I forgot to mention > that subscripts are allowed and you can't localize a subscripted > parameter. That's a fair argument for not making the parameter local. Subscripts could be useful for something like: print ${{a[i]} i=2} If we want automatic local for the subscript then maybe ${{a[]} REPLY=2} While ${{arr} ... } does return arrays, it doesn't appear to be possible to force array output from ${| ... } In mksh: print ${|REPLY=(one two)} does just print "one". But various forms like ${${|REPLY=(one two)}[1]} return just "n" I have built zsh with your latest patch and have not found any issues with any tests I've thrown at it. Perhaps worth including in a test case is the following which does break after running the echo. while :; do; echo ${|REPLY=x;break}; done Oliver