On RHEL6 and CentOS 6, /etc/bashrc
sets PROMPT_COMMAND
here:
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
fi
All of these options, as far as I know, are printed invisibly. What is the use of this?
I know that PROMPT_COMMAND
is to be executed before display the prompt (PS1
usually). I do not understand why echoing something that is not visible is of any use.
Best Answer
\033
is the octal code for theEsc
(Escape) character, which is a good hint that the echoed strings in yourPROMPT_COMMAND
are terminal control sequences. Both sequences in your examples look like they set the terminal title touser@host:pwd
.The first case,
xterm*
sets the window name and icon title. For a detailed explanation, look at the list of xterm control sequences and scroll down until you find OSC P s; P t; ST under Operating System Controls (OSC isESC ]
and ST isESC \
).The second case is for the
screen
terminal emulator, and in the list of screen control sequences, it explains thatESC _
sets screen's hardstatus (simply put, that's the title of the screen window).