zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Glyph <glyph@twistedmatrix.com>, Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: bug report: INTERACTIVECOMMENTS option interacts oddly with shell functions in an interactive context
Date: Tue, 31 Aug 2021 07:03:54 +0100	[thread overview]
Message-ID: <20210831060354.srascacw2zk35cnm@chazelas.org> (raw)
In-Reply-To: <CAH+w=7YptHhCC5__MK4LqGMYS1UEoU92jWheG+mp-UXRenVZgw@mail.gmail.com>

2021-08-30 14:35:56 -0700, Bart Schaefer:
> On Sun, Aug 29, 2021 at 1:58 PM Glyph <glyph@twistedmatrix.com> 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


  reply	other threads:[~2021-08-31  6:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29 20:55 Glyph
2021-08-30 21:35 ` Bart Schaefer
2021-08-31  6:03   ` Stephane Chazelas [this message]
2021-09-01  3:41     ` Bart Schaefer
2021-09-01  7:55       ` Stephane Chazelas
2021-09-01 15:17         ` Peter Stephenson
2021-09-01 17:55           ` Bart Schaefer
2021-09-01 18:09           ` Bart Schaefer
2021-09-01 18:23             ` Stephane Chazelas
2021-09-01 18:41               ` Stephane Chazelas
2021-09-01 18:43               ` Bart Schaefer
2021-09-02  9:04             ` Peter Stephenson
2021-09-09  3:50               ` Bart Schaefer
2021-09-09 19:06                 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210831060354.srascacw2zk35cnm@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=glyph@twistedmatrix.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).