Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with the window title in the Terminal window on OS X:

  1. Start Terminal. Window title is "bash"
  2. Type "ssh external" to connect to an external server. Window title is "user@external:~"
  3. Type "exit". I am now back at my local machine, but the window title still says "user@external:~".

How do I make the window title return to "bash", which I assume would be correct since I have logged out of the external server and returned to my local machine?

My ~/.bash_profile has the same PS1 value:

export PS1='\w$ '

share|improve this question

You define the title by echoing a specially formulated string to your terminal.

You could define:

function update_title {
   echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" ;

and then use:


each time you want to update it.

If you want it updated "all the time", you could use your shell's support for "just-before-displaying the prompt" functions. ex, in (a decently recent) bash:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

But I find this a bit overkill : it re sets the title before every prompt, not just when needed...

share|improve this answer
So you could say the reason this happens is that the prompt is set at login, but not at logout? – forthrin Nov 26 '12 at 14:50
not exactly, but in your case it seems so. – Olivier Dulac Nov 26 '12 at 15:06
You may have it set in your login scripts? (difficult to say what exactly happen, could be set in a variety of places) – Olivier Dulac Nov 26 '12 at 15:07

Here's a function that sets the title any string you give it, or hostname and current directory if you don't provide a title. I call it "xst" for "xterm set title".

xst () 
    if [ $# -eq 0 ]; then
        echo -e "\x1b]0;${HOSTNAME}:${PWD}\x07";
        echo -e "\x1b]0;$*\x07";
share|improve this answer

Your Answer


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.