Bash 3 and line wrapping.

Written by Ren West on September 13th, 2004

I had some trouble with my command line shortly after emerging Bash 3.0. My line was wrapping at very odd places and I couldn’t really figure out why. I originally had this for a prompt:

export PS1="u@h: [$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files - $(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')] w n$ "

This will show the number of files in the current directory, as well as the size of the files. This was neat, but useless so I took it out and ended up with this:

export PS1='u@h: w n$ '

Now, this was smaller, but it still messed up my line wrap. In fact, it looked as though it was wrapping the line according the size of the prompt. Some searching in the Gentoo forums revealed that Bash wasn’t counting the characters properly, thinking my prompt was part of my command line. A post from someone who actually bothered to investigate further suggested you have to escape your entire prompt with []‘s, but also escape those with ‘s. So, my final prompt is this, which works wonderfully:

export PS1='[u@h: w n$] '

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Reddit
  • email
  • StumbleUpon
  • Google Bookmarks
 

Comments are closed.

Page optimized by WP Minify WordPress Plugin