4

My PS1 variable :

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

I understand everything except the first part \[\e]0;\u@\h: \w\a\]. What is the purpose of this part? It doesn't seem to affect my prompt. In fact my question could be reduce even more to this part : \e]0;

Gradient
  • 2,253
  • 6
  • 25
  • 36

2 Answers2

3

Escape ]0 (the \e]0 you're interested in) modifies an XTerm title bar. More at this link: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/xterm-title-bar-manipulations.html

Everything inside the []:

\[\e]0;\u@\h: \w\a\]

Is marked as a non-printing character, so bash can do the right thing with line wrapping, etc. In this case that means "put the current user@hostname and current working directory in the title bar". The \a is a bell character.

chepner
  • 497,756
  • 71
  • 530
  • 681
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • The link doesn't talk about Escape 0. There is only info for Escape 1 and 2. Why is there a bell character at the end? – Gradient May 08 '13 at 05:32
  • Yes it does, it's right there in the example. When the bell character is there is a question for the person who wrote that prompt string in the first place. Maybe he likes beeps. – Carl Norum May 08 '13 at 05:48
  • Sorry, I misread that link myself. The bell character is ascii 7 which is the "end editing title bar" character in this context. – Carl Norum May 08 '13 at 05:54
0

You can also use the escape sequence to color your prompt.

Robert Gomez
  • 1,269
  • 9
  • 9