You are not logged in.

#1 2011-04-27 12:12:46

awells
Member
From: NW Indiana, USA
Registered: 2010-12-20
Posts: 10
Website

Unusual Bash Behavior w/ Custom Prompt

When I am using the below prompt, I am having issues with the history scrolling.  When I scroll through multiple historical commands, the first 10 characters will sort of stick on the command line, and I will end up seeing half of one command and half of another.  The weird thing is that if I hit enter, it will still take the command that is partially on the screen, so it seems to be a problem with only displaying the command.

My Prompt:

PS1='[\e[01;31m\u@\h \w\e[00m]\$ '

Preview:

[root@hostname ~]# 

For example, here is a list of my recent commands:

[root@hostname ~]# history | tail
  201  cd ~
  202  nano .bashrc
  203  nano .bashrc
  204  nano .bashrc
  205  exit
  206  nano .bashrc
  207  export PS1="\e[0;31m[\u@\h \W]\$ \e[m"
  208  nano .bashrc
  209  exit
  210  history | tail

I then hit up 5 times, which should go to command 206 in the above output, but it looks like this:

[root@hostname ~]# export PS1="\nano .bashrc

If I hit enter, it opens nano with the .bashrc file with no problem.  Also, when I backspace the above command, it will only backspace the nano command, which leaves me with this:

[root@hostname ~]# export PS1="\

I'm not sure what is wrong here - any help would be appreciated.

Offline

#2 2011-04-27 12:36:30

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Unusual Bash Behavior w/ Custom Prompt

You should always put "\[...\]" around escape sequences in $PS1:

PS1='[\[\e[01;31m\]\u@\h \w\[\e[0m\]]\$ '

Offline

#3 2011-04-27 12:51:05

awells
Member
From: NW Indiana, USA
Registered: 2010-12-20
Posts: 10
Website

Re: Unusual Bash Behavior w/ Custom Prompt

Thanks for the help - works now.  The couple blog posts that I was reading on the topic didn't mention enclosing the escape sequences, but now I know. smile

Offline

Board footer

Powered by FluxBB