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: Wed, 1 Sep 2021 08:55:43 +0100	[thread overview]
Message-ID: <20210901075543.7v2vd4vk47qw4yrr@chazelas.org> (raw)
In-Reply-To: <CAH+w=7Z8rhQA_N_Ui+YQezDSWAa4Ro_4fsrNdjz6ZCz+SE3cKQ@mail.gmail.com>

2021-08-31 20:41:57 -0700, Bart Schaefer:
> On Mon, Aug 30, 2021 at 11:03 PM Stephane Chazelas
> <stephane@chazelas.org> 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


  reply	other threads:[~2021-09-01  7:56 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
2021-09-01  3:41     ` Bart Schaefer
2021-09-01  7:55       ` Stephane Chazelas [this message]
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=20210901075543.7v2vd4vk47qw4yrr@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).