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 30559 invoked from network); 31 Aug 2021 06:04:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Aug 2021 06:04:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1630389859; b=iQ+l5N6Ovj5LM6nGElmBgEMVWdd8KcVNtGIIWwbPsqaGYo2d/9CNBa+UyqEpAxnRA4tx9YDhxe wvyJH/lZyLSJ6ztGRvhNA9O7RhyeUORrIaVwMdhdn+mTQ8KORHVBya5YDXWFF3+TA3ZMY11ugl DEbW6xGRBJhGtEG8UC2ybqA1ody4OgttdGI4h4c/CU9S7kcdRse4AEWdBlwuxBCCuKpukm3b+d FX4f4/C7r401zwg55IQN402+ppyXHdPqWVQUxyuC2A6gAj4hE5c1Eojs2ISVPpbqk7Q+vKgSeZ NaJP0Bbog1e0Z2umPfsBdT70B7MMvUlQlMmPy3B2OLmA0A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay1-d.mail.gandi.net) smtp.remote-ip=217.70.183.193; 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=1630389859; bh=qi1tYKlcc2QzVPoQwjVFdmciEqTs3gf+wEGdBgcoVS8=; 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=OVBjVsDPceydk8M8zBqruc1eKthzQqrNtjEUh5uGYMP1tYSY2rqrBHDlfhbEon/adOuz8GsO7T xR8qlpcwR9/SBZd6+LZ5gv9v6C7tECX85OCOd4y4V+EbGlgFBqOUVoS0LnipqkxcMl1CnmVS8X zN6dFjBmSTIr3oz2PrPpE4dukBdlNcGJggmZplY3yTGT9j/cr8LqaKJCOMr71NbiwI4paffvlL T2p5gOuVMY8d8zBIg9e3HoqExkQu+PV4U8WrqsepNqIHhaqp2lAXg9yzcbS0MxFjx/Gdta++2T Zm9mVFgfYggKPHNYgoo04XR/sXClVypm68M0fa5zIuepFw==; 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=7pi9rpyV5tDSjOzlMgEWHDOQgTIzwUTGJgTPMTBKR1k=; b=sy+TfN0VnDqlEmubkPqfgBTBfI pDJC1nk9GumyShjNM+zSlhxloeqABwPAd/KKajOqxdw82zMtgCH6BOJTOpWLChzCYSUXxhJERGZ+l EDUIScqO1V0beYOzjDpSlUBexPRE/fn/Rvts19QhrQwi3rPUKdcquNCRAiu7ja0KbM8MQYhF8kT2Y qJJs4OYN0QoyTIi4RG9G67cDuFNU1mu+B8VqthyzQ6/OeBGnfH52YPef74nDUx24dwYpjwPBs+kou R1LoSRnIQP3X1yXEv8vQTaFTf6TGwB5yzAzVddQEpC9iD24u+bb85h68K6pvHSDQIy2TrTFIrgqeb OWqCx2SA==; Received: from authenticated user by zero.zsh.org with local id 1mKwsc-000EAZ-U9; Tue, 31 Aug 2021 06:04:18 +0000 Authentication-Results: zsh.org; iprev=pass (relay1-d.mail.gandi.net) smtp.remote-ip=217.70.183.193; dmarc=none header.from=chazelas.org; arc=none Received: from relay1-d.mail.gandi.net ([217.70.183.193]:20799) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1mKwsG-000DrP-HZ; Tue, 31 Aug 2021 06:03:57 +0000 Received: (Authenticated sender: stephane@chazelas.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 65BDC240008; Tue, 31 Aug 2021 06:03:54 +0000 (UTC) Date: Tue, 31 Aug 2021 07:03:54 +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: <20210831060354.srascacw2zk35cnm@chazelas.org> Mail-Followup-To: Bart Schaefer , Glyph , Zsh hackers list References: <391FB007-1453-44CF-A990-280C59750F65@twistedmatrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 49338 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-30 14:35:56 -0700, Bart Schaefer: > On Sun, Aug 29, 2021 at 1:58 PM Glyph wrote: > > > > Comments in sample_function are interpreted normally, but comments *inside* the "bogus" expression will be interpreted as executing in an interactive context > > Hm, well, this is quite obviously intentional based on the code that > interprets $(...) expressions. The only way I can think of to change > it without breaking the behavior of $(...) typed at the actual command > line, would be for "source" and related operations to put > INTERACTIVECOMMENTS into the "sticky" emulation context during parsing > of the file (even if it was off in the parent shell). > > That is, if "source" et al. always behaved as if > > emulate $(emulate) -o interactivecomments -c 'source ...' > > then comments in $(...) and related contexts would be ignored as if > they were parsed during the "source" command instead of during the > execution of the substitution. > > But that could have some pretty confusing side-effects for functions > that want to examine $options (for example). > > Incidentally, you almost certainly want > > setopt LOCALOPTIONS INTERACTIVECOMMENTS > > in any functions where you intend to put comments inside $(...), > otherwise you will propagate INTERACTIVECOMMENTS into the parent > shell. But that used to work OK, up to 5.4.1 at least, and also applies to echo $(#comment) outside of functions. ~$ echo 'echo `# c`' > a ~$ . ./a ./a:1: bad pattern: # I would say it's a bug and a regression or at least a drastic change of behaviour since the documentation seems to be silent on that aspect. It used to work OK even for functions, as comments were always recognised inside command substitution even in interactive shells with interactive_comments off: 5.1.1% echo 'f() { echo `# c`; }; f' > a 5.1.1% . ./a 5.1.1% f 5.1.1% which f f () { echo `# c` } 5.1.1% echo `# c` 5.1.1% echo $(# c cmdsubst> ) 5.1.1% [[ -o interactive_comments ]] || echo no no Was mentioned again at https://unix.stackexchange.com/questions/666931/command-not-found-in-sourced-multiline-command-with-comments Comments are still recognised today (5.8) inside process substitution in interactive shells: $ cat <( echo test # comment ) test See how the ")" is still found as "#" is not considered as a comment by the outer shell, but the comment is still stripped by the subshell. $ set -o interactivecomments $ cat <( echo test # comment ) cmdsubst> ) test -- Stephane