[colug-432] bash history broken

Rob Funk rfunk at funknet.net
Wed Dec 28 18:00:36 EST 2011

On Wednesday, December 28, 2011 05:38:51 PM Rick Hornsby wrote:
> Having some trouble with bash history navigation.  When using the up
> arrow to scroll back through the history, sometimes it doesn't
> correctly erase.  To display the next entry, and the position of the
> cursor gets munged.  Instead of erasing the whole command, it erases
> most of it, and then starts writing the new command onto the line.

I usually run into the problem when I get output that doesn't end with a 
newline. The quickest way to recover from that when it happens is to hit 
control-L to clear the screen.

> I thought I found something where the prompt coloring was being done
> in a really weird way (using expansion of tput commands), but I fixed
> that and no luck.  I just figured out that if I set PS1="# ", I can
> make the problem go away.  As soon as I reset PS1 using source
> ~/.bash_profile, the problem comes back.
> Is there something about this PS1 that seems it could cause the
> behavior described?
> PS1='[\u@\e[0;36m\h\e[0m \W]# '

Expanding tput commands is actually the better way to do it, since it's more 
portable to other terminal types than putting raw terminal controls in there, 
as well as being much more readable.
Either way, you should wrap all your terminal controls in \[ and \], to tell 
bash that the characters within don't take any space.
So a simplified version of my prompt setting is:
PS1="\[`tput smso`\]\h \@\[`tput rmso`\] \w\[`tput smul`\]\[`tput rmul`\]\\$ "

> I found this
> http://jongartman.tumblr.com/post/5049206374/term-ps1-and-bash-history,
> but changing the TERM from xterm to xterm-color, linux, or ansi
> doesn't seem to help.  I'm pretty sure it is something to do with the
> color handling of PS1, but I posted the rest of the output from set
> below just in case.

What are you using as your actual terminal? (not the TERM variable, but the 
terminal program itself?)
Are you setting TERM explicitly anywhere, or just letting it take the default?
Your problem may be with the TERM setting, but it has to match what your 
terminal actually handles.

> USER=root

You're logging in as root? Yikes! You do know sudo, right?  :-)

More information about the colug-432 mailing list