I have a bash command prompt like this:
someone@some-host:~$
I checked the PS1
:
echo $PS1
It shows this:
\[\e]0;\u@\h: \w\a\]${debian_chroot: ($debian_chroot)}\u@\h:\w\$
How to interpret it? Why is it so complex?
I thought "\u@\h:\w$"
should be enough. And I tried to set PS1 to it. It works the same or at least looks so.
CodePudding user response:
How to interpret it?
\[ ... \]
is interpreted by Bash as not visible. It matters if you want for example Home key to jump to the beginning of the line but right after prompt. Bash has to know, how many characters to jump to place the cursor right after the prompt, so it has to know how many characters were printed when printing the prompt.
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Controlling-the-Prompt
\e]0;\u@\h: \w\a
sets the title of your terminal. https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences
${debian_chroot: ($debian_chroot)}
Expands to the string (<value of debian_chroot>)
when variable debian_chroot
is set, otherwise expands to nothing. Basically it adds (
)
to the value of debian_chroot
, when it is set to display it nicely. https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion