LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 10-07-2006, 08:03 PM   #1
Krelian
LQ Newbie
 
Registered: Jun 2006
Distribution: Mandriva
Posts: 16

Rep: Reputation: 0
bash PS1 problems


I'm having problems with bash and PS1. I like to have my bash prompt a different color than the rest of my terminal, so I have PS1 set as follows in .bashrc:

export PS1="\e[0;36m\]\u@\h: \w>\e[0m\]"

which gives me a prompt that looks like this:
Code:
brt381@cytosine: ~>
... which is how I want it. However, I have the following problem: whenever I type a long command, instead of scrolling forward to this next line as it should, bash instead starts overwriting the current line! For example, if I type "this is a long command which will stay on this line", this is what happens:
Code:
ine381@cytosine: ~>this is a long command which will stay on this l
This is extremely irritating. If I remove the parts of the PS1 above that involve color, this problem disappears. However, I like having the prompt a different color and would like to keep it that way. Can anyone identify a problem in the above PS1, or have any other ideas on how this problem might be fixed?

Thanks in advance.
 
Old 10-07-2006, 08:13 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
This is my prompt:

# bash-specific settings
ROOT_UID=0
if [ "$UID" -eq "$ROOT_UID" ]
then
PS1="\[\033[31;1m\]\u \d] \\$\w\n \[\033[0m\]"
else
PS1="\[\033[34;1m\]\u \d] \\$\w\n \[\033[0m\]"
fi

Notice this part: \\$\w\n

The prompt shows me color coded root or user, as well as pwd, then ends with a newline and color change. End result: if I'm root, my prompt is red (warning); if user, blue ('s cool, dude). Newline puts the cursor under the prompt, and resets color to normal for my term.

Oh! Did I mention that I have this in both root and user .bashrc?

For more info on bash prompts, have a look at the BootPrompt HOWTO.

Last edited by bigrigdriver; 10-07-2006 at 08:22 PM.
 
Old 10-07-2006, 09:16 PM   #3
Krelian
LQ Newbie
 
Registered: Jun 2006
Distribution: Mandriva
Posts: 16

Original Poster
Rep: Reputation: 0
That's a cool idea to have different colors for root and nonroot.

This is what I have now in .bashrc:
Code:
ROOT_UID=0
if [ "$UID" -eq "$ROOT_UID" ]
then
     PS1="\033[31;1m\]\u@\h: \w>\[\033[0m\]"
else
     PS1="\033[34;1m\]\u@\h: \w>\[\033[0m\]"
fi
...and I still have the same problem: when I type a long command, bash starts overwriting the current line when it gets to the end instead of going to the next line. IE:

Code:
 is annoyingine: ~>this is a long command which goes to the next line, which
Notice that part of my prompt has been overwritten.

It works OK if I have it as you do, with the command going on the next line, but I'd prefer the command to appear on the same line as the prompt. So can you see anything wrong with the above that would cause bash to do this?

Thanks again for your help.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remember xterm $PS1 blueAlien Slackware 11 04-14-2009 06:09 PM
Korn Shell PS1 c19h28O2 Linux - Newbie 4 04-25-2006 06:56 AM
help i can't save my PS1 setting Paxmaster Linux - Software 3 07-17-2004 10:39 PM
$PS1 different in X and prompt codec Slackware 7 06-27-2004 04:42 PM
PS1 variable wogga Red Hat 2 05-26-2004 05:39 PM

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

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