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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6450 invoked from network); 1 Sep 2021 07:56:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Sep 2021 07:56:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1630482979; b=naa22pyaUfw6xSqMTToWtuFJ55NGk9bWWEVY1zabVYxiLuXjxFGkVCltDjPOrF8pbD1JcPszv/ jJES1m3BxvZxiXvwsN8Go5y+sLVzVswAVd/JDJYJXBQ+AyD4eO3h9YTUKs+JuhDFxKk+Hwfftx w7JMG/v/fBQkz67dyXyvwXwW2csPk259YUyMpD6VJZXugwWcajeWSa8B5i/VlUiZOE2EdOWf12 J/cu8kteu+tLrFQKKlbSrDtxAMrsrgQ8S6QdbT4N2YBThEWq4PUiTCg7E2E+Uzad0x9rwCe177 XsL13XCdOZWDs9TceJCq0bInXqVZb8hZT2omBt2yuLhAjQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay2-d.mail.gandi.net) smtp.remote-ip=217.70.183.194; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1630482979; bh=7rDnaQavECC7qdK53RR8EKwZdKL2YsFu+VuGSPtI6qE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=YzDOdhb0k6ZhhzRRW85CONm4laUuVPIb24sqyfPJV/G+3A+1374f1lnGi53Ktd139G3Ee/qaFw 3RmbgtJUMg/nXE/IZJppDJxiYJsogWa+ETqpxk5MQHGU7RxqldJF9IirKAi//XRdKfO/BtDU0U 9njb/xZARwKKk/2uk5Qrt3eL5M4Ju3QFB6BbCepzE7T1uTGIcL4KTKIeGB6W3bx/YmW8MJPZHX oILpIgMjlro0ZEh1OPfZ5UbkTXs1p+awzvKnRiphT9h7NqXLoYjKKULu8eloNEMaws45SqUD9m CnP0E1ah/petLDBZKW4kOJvdi4MBId/p08/i5lOKk9q6tg==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=lqQahOjUpz/o9l2Yotr7xbwE2bRTb3LyQdWWAt1F0js=; b=YS6G49+6h72Jxmh1CaG34/8T3K sLpKBKp2Z47sBYWT9DUH9rAecE6rm85PpVmWLp6Olj9I8/rJwsw8I7TFI07m/auKaqZdgUOcLgs/7 2bQVPhm6NYznf8brcbG61N7h74ODuK1bHlsi4HMFlj85STE6ay3+tPuHT8I60JJ3/Iw+OBtijnU6Y UtpJ0IteVxHK65TWSpf7RqZ7qsoB33stpBB2YEa8wNGRqZi/Vp3Bqt9TvFkdRFCDmgi8APKmJMRJD GBdUtQ1Gm8y3e21WwXfTVDzy5qow4JpKqVryyLBRqthYOYLd9E657noCXVw+D7X7hrjEybDyWheAc 7woZR6eQ==; Received: from authenticated user by zero.zsh.org with local id 1mLL6Y-000KEO-K2; Wed, 01 Sep 2021 07:56:18 +0000 Authentication-Results: zsh.org; iprev=pass (relay2-d.mail.gandi.net) smtp.remote-ip=217.70.183.194; dmarc=none header.from=chazelas.org; arc=none Received: from relay2-d.mail.gandi.net ([217.70.183.194]:61893) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1mLL62-000Jvi-Uc; Wed, 01 Sep 2021 07:55:47 +0000 Received: (Authenticated sender: stephane@chazelas.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id C373B40002; Wed, 1 Sep 2021 07:55:43 +0000 (UTC) Date: Wed, 1 Sep 2021 08:55:43 +0100 From: Stephane Chazelas To: Bart Schaefer Cc: Glyph , Zsh hackers list Subject: Re: bug report: INTERACTIVECOMMENTS option interacts oddly with shell functions in an interactive context Message-ID: <20210901075543.7v2vd4vk47qw4yrr@chazelas.org> Mail-Followup-To: Bart Schaefer , Glyph , Zsh hackers list References: <391FB007-1453-44CF-A990-280C59750F65@twistedmatrix.com> <20210831060354.srascacw2zk35cnm@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 49344 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: 2021-08-31 20:41:57 -0700, Bart Schaefer: > On Mon, Aug 30, 2021 at 11:03 PM Stephane Chazelas > wrote: > > > > But that used to work OK, up to 5.4.1 at least, and also applies > > to echo $(#comment) outside of functions. > > +Changes from 5.4 to 5.4.3 > +------------------------- > + > +The effect of the NO_INTERACTIVE_COMMENTS option extends into $(...) and > +`...` command substitutions when used on the command line. Previously, > +comments were always recognized within command substitutions unless the > +comment character "#" was disabled via reset of $histchars. > > Thread started with workers/41656 (September 2017) about writing > aliases that start with "#" and being able to use them inside $(...). Thanks. That still leaves a few problems: First and more important, comments are meant to be stripped in scripts, whether they're executed or sourced, whether that's from an interactive shell with interactivecomments or not. If not, you wouldn't be able to have comments in any script you intent to source other than by adding something like set -o interactivecomments at the beginning (and restoring upon return). So here, I'd say: ~$ cat a echo foo # comment echo $( echo bar # comment ) ~$ . ./a foo ./a:3: bad pattern: # is clearly a bug (regression). Once that's fixed there's still the problem of delayed (second) parsing of code inside command substitution. Which would still cause functions defined in sourced scripts to fail (or behave differently) when invoked from interactive shells. It seems to me the interactivecomments option should be honoured at time of reading code, and comments stripped then when it's on. $ set -o interactivecomments ~$ f() { echo foo # comment echo $( echo bar # comment ) } ~$ f foo bar ~$ set +o interactivecomments ~$ f foo f:3: bad pattern: # $ which f f () { echo foo echo $( echo bar # comment ) } IMO, that function f should have been stored as: $ which f f () { echo foo echo $( echo bar ) } As already noted, there's also a consistency problem in that while comments are no longer stripped in command substitutions with interactivecomments off, they still are in process substitutions (tangentially related, Also note the misleading PS2 output in: $ cat <( cmdsubst> ) (expected procsubst> / prcsubst>...) -- Stephane