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 19:07:03 -0400

On Sun, Jul 04, 2021 at 10:04:46PM +0200, lisa-asket@perso.be wrote:
> >From: Greg Wooledge <greg@wooledge.org>
> 
> >You don't want them in PS0. Only in PS1.
> 
> Thank you, the two strange characters no longer show up after removing \[ and 
> \]
> 
> from PS0.  Strange thing that one sometimes uses \[ and \], and sometimes not.

As I said before, the purpose is to let bash know where the cursor is,
since bash has to track that itself.

PS1 requires this treatment, because bash prints the characters of PS1
to the terminal before accepting user input.  It needs to know where the
cursor is during said user input.

PS0 is printed *after* user input is completed.  At that point, bash no
longer tries to track the cursor -- it can't.  Some command is executing
over which bash has no oversight.

When the command has completed and bash is ready to assume control again,
bash (once more) assumes that the cursor is in the leftmost column.

Therefore, \[ and \] don't have the same meaning in PS0 that they have
in PS1.



reply via email to

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