2026年6月11日(木) 1:04 Chet Ramey <[email protected]>:
> > $ PS4='+\[$\]-'
>
> Why do this, other than to cause yourself problems?

I replied the same to kre, but the above is just a made-up example to
demonstrate the *behavior change* in commit 1e9f5e10. I'm not saying I
wanted to do the above. In that argument, I didn't intend to
illustrate the original issue, but I tried to argue the behavior
consistency between 5.3 and the current devel. If you want a more
likely structure, I can adjust the example by making it closer to the
original issue:

  # In some helper library for PS1, etc.
  ps_elem1='\[\e]0;xxx\e\\\]$(echo some)'
  ps_elem2=...
  ...

  # Re-use ps_elem1 for PS4
  PS4="$ps_elem1 "

Then, one can observe how the last change in commit 1e9f5e10 affected
the promptvars application.

  $ bash-5.3 --norc
  $ ps_elem1='\[\e]0;xxx\e\\\]$(echo some)'
  $ PS4="$ps_elem1 "
  $ set -x
  $ echo hello
  some echo hello
  hello
  $ exit

  $ bash-devel --norc
  $ ps_elem1='\[\e]0;xxx\e\\\]$(echo some)'
  $ PS4="$ps_elem1 "
  $ set -x
  $ echo hello
  $(echo some) echo hello$(echo some) echo hello
                                                hello
  $ exit

> Maybe a simple admonishment in the man page will be sufficient.

Does that mean you stopped reading my previous reply at the third line
`$ PS4='+\[$\]-''. Could you read this part?

> I can agree that the current behavior is one possible consistent
> behavior, but could you take this as ``a feature request'' for another
> consistent behavior? That is, the removal of \x01 and \x02 is
> performed at the very last stage so that the behavior of the
> `promptvars' processing of PS0 and PS4 is unaffected.
>
> If you think it is not consistent with `the --noediting PS1', I think
> one can switch the behavior depending on `--noediting'. If line
> editing is disabled, \[\] may produce an empty string from the
> beginning. Otherwise, \[ and \] produce \x01 and \x02, which will
> later be properly processed or removed at the final stage. Actually, I
> think it is more consistent that `the --noediting PS1' behavior would
> be modified to match the proposed behavior of removing \x01 and \x02
> at the very final stage.

--
Koichi

Reply via email to