Date:        Mon, 8 Jun 2026 23:16:04 +0900
    From:        Koichi Murase <[email protected]>
    Message-ID:  
<CAFLRLk9+Rf8o3wrmuXnODmKe8W-zf=e-+jo3bm4yqgd1f1t...@mail.gmail.com>

  | $ PS4='+\[$\]-'
  | $ set -x
  | $ echo hello
  | +$- echo hello
  | hello

If that's what you're trying to achieve, then

        PS4='+\$-'

will do it, and what's more, work the same way in PSn (for any n), and
whether or not line editing is enabled.

If you want to output a bold - after a non-bold + then

        PS4="+\[$(tput bold)\]-"

(though perhaps it also needs a tput sgr0 in there as well to disable bold
after the "-").   In PS4 the \[ \] are pointless, and should simply vanish
(same as what I understand PS0, and perhaps PS3 (??)) but including them
allows the same string to be used for PS1 or PS2.


As I understand the bash rules, between the \[ and \] in prompts there
are only supposed to be data which affects the display mode of the
terminal (change colour, bold, blinking, ...) and do not cause any
actual visible output.   If you have a '$' there (alone) then that breaks
the rules, and I think anything is reasonable as a result.


>From what I can tell (I don't actually use any of this) what bash is
doing now, as described, is exactly what it should be doing (unless it
should be treating PS3 the same as PS1 and PS2), and there is no need at
all for anything different.   \[ and \] are not intended to be some kind
of generic quoting chars in prompts, a simple \ already does that.

kre


Reply via email to