LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-19-2010, 11:12 PM   #1
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Rep: Reputation: 56
Bash prompt displays twice


I'm playing around with my prompt, and for some reason under certain conditions part of the prompt is output twice. I have no idea why.

- When my terminal window isn't maximized it always outputs the prompt correctly.
- When the window is maximized it outputs the prompt correctly when I enter an empty command (ie, when I just hit enter).
- When it is maximized and I enter any command, it outputs the second line of my prompt twice.

I'm using urxvt.. I tested in xterm and it seems to work correctly, so I guess it's an issue with urxvt. Any clue as to where I should start digging?

Thanks!

My prompt code:
Code:
#!/bin/bash

function redblue {
	local       BLUE="\[\033[0;34m\]"
	local        RED="\[\033[0;31m\]"
	local  LIGHT_RED="\[\033[1;31m\]"
	local      WHITE="\[\033[1;37m\]"
	local LIGHT_GRAY="\[\033[0;37m\]"
	case $TERM in
		xterm*)
			TITLEBAR='\[\033]0;\u@\h:\w\007\]'
			;;
		*)
			TITLEBAR=""
			;;
	esac

	PS1="${TITLEBAR}\
	$BLUE[$RED\d, \t$BLUE] [$LIGHT_RED\w$BLUE]\n\
	$BLUE[$LIGHT_RED\u$BLUE@$LIGHT_RED\h$BLUE] $RED\$$LIGHT_GRAY "
	PS2='> '
	PS4='+ '
}
I started with code from this site: http://www.gilesorr.com/bashprompt/prompts/

This is what the prompt is supposed to look like:
Code:
	[Fri Feb 19, 23:57:58] [~]
	[matt@hopper] $ cd /var/log
	[Fri Feb 19, 23:58:01] [/var/log]
	[matt@hopper] $ ls                                                      
Xorg.0.log	debug	 lastlog   removed_packages  secure   wtmp
Xorg.0.log.old	dmesg	 maillog   removed_scripts   setup
btmp		faillog  messages  sa		     spooler
cron		httpd	 nfsd	   samba	     syslog
cups		iptraf	 packages  scripts	     uucp
	[Fri Feb 19, 23:58:02] [/var/log]
	[matt@hopper] $
This is what it looks like when it displays incorrectly:
Code:
	[Fri Feb 19, 23:58:59] [~]
	[matt@hopper] $ cd /var/log/
	[Fri Feb 19, 23:59:06] [/var/log]
	[matt@hopper] $ 
        [matt@hopper] $ ls
Xorg.0.log	btmp  cups   dmesg    httpd   lastlog  messages  packages	   removed_scripts  samba    secure  spooler  uucp
Xorg.0.log.old	cron  debug  faillog  iptraf  maillog  nfsd	 removed_packages  sa		    scripts  setup   syslog   wtmp
	[Fri Feb 19, 23:59:08] [/var/log]
	[matt@hopper] $ 
        [matt@hopper] $
[Edit: sorry if this isn't the best forum for this post, I wasn't sure where to put it!]
 
Old 02-19-2010, 11:44 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I'm not sure what-all is not quite right about this code, but it doesn't work for me, even remotely, in xterm.

A couple tips (Bash specifics, but may work for other too):

1) (this is maybe more an FYI than anything, but thought I'd point it out) defining a function doesn't need the "function" keyword, so this is fine:

Code:
redblue () {

  code in here...
   more code.. blah blah
  code code code...

} #end of function
2) I am finding problems with the way you are creating your colors. To create a color, you merely need:

Code:
BLUE="\033[0;33m"
Note that I have not added any [brackets] around that; it will work just fine like this. When I try it your original way, the escaped brackets such as "\[blah\]" are being interpreted by the shell as test commands (test being the [ symbol), so it acts very strange for me in that regard, and my prompt ends up beginning with the word "test".

So, whether or not the "function" keyword is causing any trouble, I would definitely revisit those escaped brackets in your COLOR variables. I don't see any actual code on that page you linked, so if there's some specific example that would explain where you're coming from, please do post a link to that.

Hope this helps!
 
1 members found this post helpful.
Old 02-19-2010, 11:57 PM   #3
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Original Poster
Rep: Reputation: 56
Oh my god, thank you! Removing the escaped square brackets fixed it!
 
Old 02-19-2010, 11:59 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Nice one! Glad you got it sorted

Sasha
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Edubuntu from live CD displays login prompt edwardp Ubuntu 2 01-20-2008 10:29 PM
What to do at the bash-prompt? daav Linux - Newbie 2 10-18-2006 03:52 AM
bash prompt subG Slackware 6 01-18-2006 04:43 PM
help with bash prompt everythingand2 Linux - Newbie 7 12-06-2003 04:28 PM
Bash Prompt mandraketux Mandriva 2 11-28-2003 10:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration