2

This is my PS1 prompt:

export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " 

That shows perfect in remote (SSH) console (PTS):

luis@Chomsky:~$ 

Can not show it, but the full prompt is in violet color.
The problem is: in local (TTY), it shows some ugly:

;luis@Chomsky: ~luis@Chomsky:~$ 

Can not show it neither, but the first part (from ";" to "~") has no color, and the rest is in violet color.

Additional data: 
  • Using Bash Shell:

luis@Chomsky:~$ ps -p$$ -ocmd= -bash

  • Tested in Ubuntu Desktop and Ubuntu Server v14.04 LTS.
  • Tested (at least) in a portable ASUS EEE PC and on VirtualBox virtual machine.
  • I use to add the export PS1= line at ~/.bashrc.

I would like to know why is this happening and how could I solve it.

Thanks.

4
  • What shell are you using? Are both machines using the same one? How/where are you setting PS1? Commented Nov 9, 2014 at 2:26
  • @terdon, added the requested info to the original post. Commented Nov 9, 2014 at 2:47
  • Are you doing anything to PS1 in ~/.profile? Commented Nov 9, 2014 at 2:55
  • @terdon, the command cat ~/.profile | grep "ps1" -i shows no results, so I think not. Commented Nov 9, 2014 at 2:56

1 Answer 1

2

The control sequence \e]0;TITLE\a is recognized by many terminal emulators; it sets the window title. This control sequence is not recognized by the Linux console (which doesn't have a title anyway): it sees \e]0, decides “I don't know what this means, so I'll ignore it”, and prints the following text.

You'll need to set your prompt differently depending on the current terminal.

title_text='\u@\h: \w' set_title= case $TERM in dtterm|rxvt|[Ek]term|*xterm) set_title='\[\e]0;'"$title_text"'\a\]';; screen) set_title='\[\ek'"$title_text"'\e\\\]';; esac PS1="$set_title$PS1" 
9
  • Well, it is rather complicated, but I have pasted it to a .sh script, executed, and nothing seems to have changed. At least my prompt keeps the same. Commented Nov 9, 2014 at 4:26
  • @SopalajodeArrierez Did you run this in a separate script? That won't work: the script doesn't influence its parent shell. You need to run this inside bash. This code is meant to go into your .bashrc. Since I add the title-setting code to what's already there, this should replace the existing part that adds the title-setting code. Commented Nov 9, 2014 at 4:37
  • Tested in both ways. Even on ~/.bashrc nothing seems to have changed. I put your script right after my export PS1= line. Commented Nov 9, 2014 at 5:21
  • @SopalajodeArrierez Put set -x before the snippet and set +x after, and tell me what is printed when you run bash (it'll start with + title_text='\u@\h: \w') as well as the resulting value of PS1 (edit your question or use pastebin.com or whatever you prefer). Commented Nov 9, 2014 at 6:45
  • Here you have, thanks you: pastebin.com/ish0Epnu Commented Nov 9, 2014 at 15:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.