help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing PSI and PS0 leads to four characters at beginning of user i


From: Greg Wooledge
Subject: Re: Changing PSI and PS0 leads to four characters at beginning of user input
Date: Sun, 4 Jul 2021 15:32:58 -0400

On Sun, Jul 04, 2021 at 09:11:54PM +0200, lisa-asket@perso.be wrote:
> \[ \]  to enclose the tput commands?  I thought those were only used when 
> using
> 
> escape sequences only.

It doesn't matter whether the characters are hard-coded or produced by
an expansion.  The point is that bash needs to know where the cursor is
at all times.  It CANNOT ask the terminal, because terminals simply
don't work that way.

Bash tracks the cursor position by assuming that each time it prints
a prompt, the cursor was in the leftmost column to begin with, and then
keeping track of each character that it prints, either as a result of
expanding the prompt, or as a result of the user typing on the keyboard.

So, for every character in PS1, bash needs to know whether that character
moves the cursor forward, or not.  You have to tell it, by enclosing any
characters that do NOT move the cursor inside \[ \].  Otherwise, bash
has no way to know.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]