LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-01-2011, 02:22 PM   #1
WyattOil
LQ Newbie
 
Registered: Jun 2011
Distribution: Suse 11.4
Posts: 13

Rep: Reputation: 10
Question Bash prompt. It looks fine initially, but there seems to be a hidden error.


I've written custom prompts for several boxes but this one has an error I just can't identify and need a second set of eyes to help solve it.


I've set the following as my prompt:
PS1="\[\e[30;42m\]\u@\h\[\e[0m\]\[\e[30;47m\] \#\]\[\e[0m\]\[\e[32;1;40m\]\w>\[\e[0m\] "
(hostname/un obscured & image enlarged slightly to make it easier to read.)

Everything looks fine initially as you can see here:

1- It sets the username@host in back on green text.
2- It then changes to an off-white an prints the command number for the terminal.
3- Next, changes to a green on black font and prints the working directory.
4- Finally is prints a ">" character and a space.


The problem occurs when I try to "up arrow" to reuse and/or edit a prior command. It prints the prior command fine, but if I arrow over to edit the command sometimes the first character can not be deleted from displaying as you can see in the following composite screen-shot


Here I did a simple ps and piped it through grep. After getting the output, I up-arrow to repeat the command. As you can see by the second section the cursor only goes back to the "s" in ps. The "p" can not be deleted. Hitting enter just displays a new line, so the "p" was just a ghost being displayed and not really there.

Can anyone else see why that randomly occurs? I must have a goof in the prompt, but I sure as heck can't see it.

Thanks in advance.
 
Old 06-01-2011, 03:17 PM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Your original prompt had an unbalanced "\]". Also, you don't need to put "\[\]" around every control code (i.e. you did "\[<control code>\]\[<control code\]" when "\[<control code><control code\]" would do). You put them around text that doesn't move the cursor forward, so that bash knows where to position the command's test when using up-arrow history. Finally, you don't need to reset the color before changing it again.

Try this:

Code:
PS1="\[\e[30;42m\]\u@\h\[\e[30;47m\] \#\[\e[32;1;40m\]\w>\[\e[0m\] "
 
1 members found this post helpful.
Old 06-01-2011, 06:55 PM   #3
WyattOil
LQ Newbie
 
Registered: Jun 2011
Distribution: Suse 11.4
Posts: 13

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by MTK358 View Post
Your original prompt...
Wow, thanks so much.

Marking this solved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i connect to a hidden wireless network from command prompt? Pooped Linux - Networking 5 01-24-2010 05:07 PM
bash: mv hidden and not hidden files lupe Linux - General 4 06-22-2009 01:27 PM
Set up Red Hat Linux Fedora Core 4 fine, initially but. . . Henry777 Linux - Newbie 5 07-08-2008 02:47 PM
Hidden Linux/GNU/Bash gems for the self learner? randomsel Linux - General 1 06-26-2008 06:34 PM
Bash scripting problem: Can't get a list of all files, including hidden ones oxi Programming 24 03-12-2007 06:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:36 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