Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 132988 - Bash prompt overwriting program output
Summary: Bash prompt overwriting program output
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-11 02:20 UTC by Tommy McDaniel
Modified: 2007-05-04 11:31 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tommy McDaniel 2006-05-11 02:20:27 UTC
When I type "echo -n Test", the output I am getting is:

tommstein@Morpheus ~ $ ~ $

The expected output based on how Bash has always behaved for me is:

Testtommstein@Morpheus ~ $

If you output a sufficiently long string, you can see the end of it hanging past the prompt. What seems to be happening is that Bash is overwriting the output with its prompt, by writing it at the beginning of the line even if there is output on the line. To confirm that, try "echo -n Test; sleep 3". More specifically, the fact that the cursor is placed before the extra "~ $" part at the end (of my specific example) makes me think that it is first writing the prompt in the usual way, and then resetting the position to the beginning of the line and writing it again. Hopefully this isn't a new "feature." I have confirmed in the #gentoo IRC channel that others are getting the same behavior (one of the people was using zsh, and I don't know whether that's the expected behavior of zsh or whether that indicates that this bug isn't actually in Bash, but rather in a common library used by Bash and zsh). Here is my emerge --info:

Portage 2.0.54 (default-linux/amd64/2005.0, gcc-3.4.5, glibc-2.3.6-r3, 2.6.15-gentoo-r1 x86_64)
=================================================================
System uname: 2.6.15-gentoo-r1 x86_64 AMD Opteron(tm) Processor 246
Gentoo Base System version 1.6.14
dev-lang/python:     2.3.5-r2, 2.4.2
dev-python/pycrypto: 2.0.1-r4
dev-util/ccache:     [Not Present]
dev-util/confcache:  [Not Present]
sys-apps/sandbox:    1.2.17
sys-devel/autoconf:  2.13, 2.59-r7
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r1
sys-devel/binutils:  2.16.1
sys-devel/libtool:   1.5.22
virtual/os-headers:  2.6.11-r2
ACCEPT_KEYWORDS="amd64"
AUTOCLEAN="yes"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=opteron -O3 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3.3/env /usr/kde/3.3/share/config /usr/kde/3.3/shutdown /usr/kde/3.4/env /usr/kde/3.4/share/config /usr/kde/3.4/shutdown /usr/kde/3/share/config /usr/lib/X11/xkb /usr/share/config /usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/eselect/compiler /etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-march=opteron -O3 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoconfig distlocks sandbox sfperms strict"
GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/linux/distributions/gentoo"
LANG="en_US.utf8"
LC_ALL="en_US.utf8"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="amd64 X Xaw3d a52 aac aalib accessibility acl acpi adns aim alsa apache2 arts audiofile avi bash-completion bcmath berkdb bidi bitmap-fonts bluetooth bonobo bzip2 bzlib calendar canna cdb cdparanoia cdr chasen cjk cli crypt cscope ctype cups curl curlwrappers db2 dba dbase dbm dbx dedicated dga dio directfb divx4linux doc dri dv dvb dvd dvdr dvdread eds emacs emacs-w3 emboss emul-linux-x86 encode esd ethereal evo examples exif expat fam fastcgi fbcon ffmpeg flac flash flatfile foomaticdb fortran freetds freewnn ftp gb gcj gd gdbm geoip ggi gif ginac glut gmp gnome gnustep gnutls gphoto2 gpm gps gstreamer gtk gtk2 gtkhtml guile hal hardened hardenedphp howl hyperwave-api iconv icq idn imagemagick imap imlib inifile innodb interbase iodbc ipv6 isdnlog jabber jack javascript joystick jpeg kde kerberos krb4 ladcca lcms ldap leim libcaca libg++ libgda libwww lirc lm_sensors lua lzw lzw-tiff m17n-lib mad maildir mailwrapper matroska mbox mcal mcve memlimit mhash migemo mikmod milter mime ming mmap mng mnogosearch motif mozilla mp3 mpeg mpi msession msql mssql mule mysql mysqli nas ncurses neXt netcdf nis nls nocd nptl oci8 odbc offensive ofx ogg openal opengl oracle oracle7 osc oscar oss ovrimos pam pcntl pcre pda pdflib perl php plotutils png portaudio posix postgres ppds pppd prelude python qdbm qt quicktime readline recode reflection ruby samba sapdb sasl scanner sdl session sharedext sharedmem shorten simplexml skey slang slp smartcard sndfile snmp soap sockets socks5 source sox speex spell spl sqlite ssl svg symlink sysvipc szip tcltk tcpd tetex theora threads tidy tiff tokenizer truetype truetype-fonts type1-fonts udev unicode usb v4l vcd vhosts videos vorbis wddx wifi wmf wxwindows xface xine xml xml2 xmlrpc xmms xorg xosd xpm xprint xsl xv xvid yahoo yaz zeo zlib userland_GNU kernel_linux elibc_glibc"
Unset:  ASFLAGS, CTARGET, INSTALL_MASK, LDFLAGS, LINGUAS, PORTAGE_RSYNC_EXTRA_OPTS, PORTAGE_RSYNC_OPTS, PORTDIR_OVERLAY

Thanks.
Comment 1 SpanKY gentoo-dev 2006-05-11 20:35:01 UTC
works fine for me with bash-3.1_p17

what is your PS1 set to
Comment 2 Tommy McDaniel 2006-05-11 22:18:30 UTC
(In reply to comment #1)
> works fine for me with bash-3.1_p17
> 
> what is your PS1 set to
> 

I've got bash-3.1_p16. PS1 is:

\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]

If it changed recently, it wasn't me.
Comment 3 PL Hayes 2006-06-18 00:37:10 UTC
Same here with p16 and p17

In the console, they seem to work normally.

Just reverted to bash-3.0-r14 and it seems okay too. 
Comment 4 PL Hayes 2006-06-21 17:58:21 UTC
Actually, reverting to bash-3.0 just makes what appears to be the same bug manifest under different circumstances. Looking through the official bash patches, the bash mailing list and the gentoo patches, it appears there have been various attempts to fix these/this bash/readline/utf-8 related problem[s], eg bug #69407 and bug #109609 but it seems they have not really been successful.



Comment 5 Martel Valgoerad 2006-06-27 04:42:29 UTC
Actualy it has something to do with bash colors. If you leave only the first color everything works correctly:

PS1='\[\033[1;32m\]\u@\h \w \$ '

If you add color host it is mangled again:

PS1='\[\033[1;32m\]\u@\h\[\033[1;34m\] \w \$ '

BUT! 

If you move the host after the second color, everything works again:

PS1='\[\033[1;32m\]\u@\[\033[1;34m\]\h \w \$ '

The bug exists whatever the locale is set. Be it en_US or en_US.utf8 it jumps to the first column on script end.
Comment 6 Martel Valgoerad 2006-06-27 04:47:07 UTC
Well, maybe some emerge info will be useful too:

Portage 2.1-r1 (default-linux/x86/2006.0, gcc-4.1.1/vanilla, glibc-2.4-r3, 2.6.16-gentoo-r9n i686)
=================================================================
System uname: 2.6.16-gentoo-r9n i686 AMD Athlon(tm) XP 2500+
Gentoo Base System version 1.12.1
dev-lang/python:     2.4.3-r1
dev-python/pycrypto: 2.0.1-r5
dev-util/ccache:     [Not Present]
dev-util/confcache:  0.4.2
sys-apps/sandbox:    1.2.18.1
sys-devel/autoconf:  2.13, 2.59-r7
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2
sys-devel/binutils:  2.16.1-r2
sys-devel/gcc-config: 2.0.0_rc1
sys-devel/libtool:   1.5.22
virtual/os-headers:  2.6.11-r5
ACCEPT_KEYWORDS="x86 ~x86"
AUTOCLEAN="yes"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-O2 -march=athlon-xp -fomit-frame-pointer -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/lib/mozilla/defaults/pref /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/eselect/compiler /etc/gconf /etc/revdep-rebuild /etc/terminfo"
CXXFLAGS="-O2 -march=athlon-xp -fomit-frame-pointer -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoconfig confcache distlocks fixpackages metadata-transfer sandbox sfperms strict"
GENTOO_MIRRORS="ftp://mirror.icis.pcz.pl/gentoo/"
LANG="en_US"
LC_ALL="en_US.utf8"
LINGUAS="en pl"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude='/distfiles' --exclude='/local' --exclude='/packages'"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="x86 3dnow X acpi alsa apache2 apm arts avi berkdb bitmap-fonts cli crypt cups dbus dlloader dri eds emboss encode esd foomaticdb fortran gd2 gdbm gif gnome gpm gstreamer gtk gtk2 hal imlib isdnlog jpeg kde kdeenablefinal libg++ libwww mad mikmod mmx motif mp3 mpeg ncurses nls nptl nvidia ogg opengl pam pcre pdflib perl php png pppd python qt quicktime readline reflection sdl session spell spl sse ssl tcpd truetype truetype-fonts type1-fonts udev unicode utf8 xml xml2 xmms xorg xprint xv zlib elibc_glibc input_devices_-acecad input_devices_-aiptek input_devices_-calcomp input_devices_-citron input_devices_-digitaledge input_devices_-dmc input_devices_-dynapro input_devices_-elo2300 input_devices_-elographics input_devices_-evdev input_devices_-fpit input_devices_-hyperpen input_devices_-jamstudio input_devices_-joystick input_devices_keyboard input_devices_-magellan input_devices_-magictouch input_devices_-microtouch input_devices_mouse input_devices_-mutouch input_devices_-palmax input_devices_-penmount input_devices_-spaceorb input_devices_-summa input_devices_-synaptics input_devices_-tek4957 input_devices_-ur98 input_devices_-vmmouse input_devices_-void input_devices_-wacom kernel_linux linguas_en linguas_pl userland_GNU video_cards_-apm video_cards_-ark video_cards_-ati video_cards_-chips video_cards_-cirrus video_cards_-cyrix video_cards_-dummy video_cards_fbdev video_cards_-fglrx video_cards_-glint video_cards_-i128 video_cards_-i740 video_cards_-i810 video_cards_-imstt video_cards_-mga video_cards_-neomagic video_cards_-nsc video_cards_-nv video_cards_nvidia video_cards_-rendition video_cards_-s3 video_cards_-s3virge video_cards_-savage video_cards_-siliconmotion video_cards_-sis video_cards_-sisusb video_cards_-tdfx video_cards_-tga video_cards_-trident video_cards_-tseng video_cards_-v4l video_cards_vesa video_cards_-vga video_cards_-via video_cards_-vmware video_cards_-voodoo"
Unset:  CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LDFLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 7 Martel Valgoerad 2006-06-27 04:57:51 UTC
Ok, I have resolved the issue:

Change this line:
PS1='\[\033[1;32m\]\u@\h\[\033[1;34m\] \w \$\[\033[00m\] '

To this:
PS1='\033[1;32m\u@\h\033[1;34m \w \$\033[00m '

I don't know what this sequence does (\[...\]) but according to bash FAQ, yu don't have to use it in order to color your prompt:

http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/c583.html
Comment 8 Benno Schulenberg 2006-11-26 05:30:44 UTC
> PS1='\033[1;32m\u@\h\033[1;34m \w \$\033[00m '

That is not the correct fix.  Try using Ctrl+R, type a letter and then Home...  The line gets royally messed up.

> I don't know what this sequence does (\[...\])

See bug #73752 comment #9.
Comment 9 SpanKY gentoo-dev 2007-02-09 06:25:20 UTC
you need the \[ and \]

see E3 in ftp://ftp.cwru.edu/pub/bash/FAQ

also, you should try using \e instead of \033
Comment 10 Peter Volkov (RETIRED) gentoo-dev 2007-04-14 06:59:35 UTC
Tommy, could you try to reproduce the bug with app-shells/bash-3.2_p15-r1? If you do, try to apply patch from bug 156292. I did not manage to reproduce this behavior.
Comment 11 Tommy McDaniel 2007-04-14 07:45:52 UTC
Well, with bash-3.1_p16, I am getting the correct results on my laptop. However, based on when I opened this bug, there's a 99% chance that I was using my currently-broken desktop. I don't know why this would happen on my desktop and not my laptop. Based on what was said in comment #4, that "it appears there have been various attempts to fix these/this bash/readline/utf-8 related problem[s]," the problem may be related to the fact that I think I set my desktop up to be more "internationalized."
Comment 12 Peter Volkov (RETIRED) gentoo-dev 2007-05-04 11:31:53 UTC
Closing then this bug report as WORKSFORME as bash-3.2 works here even on desktop machine with nls support. If you ever reproduce this bug, please, reopen then.