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.

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

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"
  • 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. – Sopalajo de Arrierez Nov 9 '14 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. – Gilles Nov 9 '14 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. – Sopalajo de Arrierez Nov 9 '14 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). – Gilles Nov 9 '14 at 6:45
  • Here you have, thanks you: pastebin.com/ish0Epnu – Sopalajo de Arrierez Nov 9 '14 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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