bash line wrapping problem

I noticed I was having a line wrapping issue with my bash prompt which really got annoying. It’s been at least a month and I finally decided to find a fix for it.

wrapping problem

My prompt in .bashrc is PS1="[\u@\e[0;31m\h\e[1;39m \W]: "
According to this post I need to wrap the escape codes with \[. So I changed my prompt to the following and all seems well: PS1="[\u@\[\e[0;31m\]\h\[\e[1;39m\] \W]: "

wrapped fix

Advertisements

16 thoughts on “bash line wrapping problem

  1. Thank you, you made my life much easier.

    Maybe you could add some explenations on your other bash options too, seem to do a nice job, it would just be nice to know what they exactly mean, without rtfm. 🙂

  2. This works okay but what about when you want to echo output such as

    $ echo -e ‘\[\e[0;32m\]’ This is green

    You get:

    \[\] This is green

    The escaped [ characters are printed.

  3. Thanks. I made the same exact mistake you did. A long time ago I made a custom bash prompt on Linux, and when I installed MSYS on Windows, I figured I would quickly throw a prompt together based on what I could remember (which apparently wasn’t enough).

    Interestingly, the problem doesn’t occur if bash is run from Windows’ own cmd (possibly because cmd isn’t a proper tty emulator?).

    Also, congrats for the high-ranking page on Google!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s