On 6/6/26 11:46 AM, Egmont Koblinger wrote:
Hi Chet,Thanks for accepting and working on my recent request at https://lists.gnu.org/archive/html/bug-bash/2026-05/msg00061.html which you aimed to address in commit 1e9f5e10b2a6f81d458936372380c870f0722ef1. Unfortunately, the new behavior of \[ \] in PS0 is still not identical to their behavior in PS1.
Well, let's look at the diff.
***************
*** 6633,6637 ****
case '[':
case ']':
! if (no_line_editing)
{
string++;
--- 6633,6637 ----
case '[':
case ']':
! if (no_line_editing || (is_prompt && decoding_prompt != ps1_prompt
&& decoding_prompt != ps2_prompt))
{
string++;
The behavior of PS0 is the same as PS4 and identical to the behavior of PS1
and PS2 prompt string decoding when readline is not enabled: the \[ and \]
escape sequences are simply ignored.
In PS1, the string undergoes two rounds of parsing (the second only if promptvars is enabled) and finally the 0x01 / 0x02 bytes (previously \[ and \] strings in PS1) are eliminated. (Thanks for pointing out that this is done in readline which is bypassed by PS0.)
There is no reason to add the 0x01 and 0x02 markers unless the prompt string is going to be passed to readline. This is what the code has always done when line editing is not active; the update extends that to prompt strings that are never going to be passed to readline.
In PS0, it seems to me that the elimination of these markers now happens between the two rounds of parsing.
See above. This is the same thing that happens when expanding PS4 as well.
In the following examples I assume that promptvars is enabled and that the terminal silently ignores the 0x01 / 0x02 bytes. Example 1: PS1='$\[PATH' The literal string $PATH (five characters) appears as prompt. Do the same with PS0. Prior to the recent change, the behavior was the same (under the hood with an invisible 0x01 byte after the dollar). With the new change, the long expanded value of $PATH is printed.
Try it with --noediting; the same thing happens.
The current devel behavior is consistent: if the prompt string is passed to
readline, the \[ and \] are converted to readline markers; if the prompt is
not passed to readline, they are ignored.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
