Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 9 down vote accepted

\033 is the octal code for the Esc (Escape) character, which is a good hint that the echoed strings in your PROMPT_COMMAND are terminal control sequences. Both sequences in your examples look like they set the terminal title to user@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 is ESC ] and ST is ESC \).

The second case is for the screen terminal emulator, and in the list of screen control sequences, it explains that ESC _ sets screen's hardstatus (simply put, that's the title of the screen window).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.