LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help Customizing Terminal prompt (https://www.linuxquestions.org/questions/linux-newbie-8/help-customizing-terminal-prompt-872612/)

EzioAuditore 04-02-2011 04:56 PM

Help Customizing Terminal prompt
 
1 Attachment(s)
Hello,

I tried customizing the terminal header today, all good but one line appears after every command as shown in the screenshot..

How do I stop this from happening?

Below is the PS1 line from ~/.bashrc file:

Code:

PS1='Welcome back. How can I help you?\n${debian_chroot:+($debian_chroot)}\[\033[1;31m\]\u@\h\[\033[00m\]\[\033[1;31m:\]\[\033[1;31m\]\w\[\033[00m\]\[\033[1;31m$\] \[\033[1;34m\] '
Thanks!

w1k0 04-02-2011 05:08 PM

Change your PS1 to something like:

Code:

PS1="`hostname`:`pwd`# "
or:

Code:

PS1="\u@\h:\w\$ "

EzioAuditore 04-02-2011 05:18 PM

Won't these remove my customizations even? I just want that Welcome line to appear only once and not repeat after every command..

MTK358 04-03-2011 12:21 PM

Quote:

Originally Posted by EzioAuditore (Post 4311812)
Won't these remove my customizations even? I just want that Welcome line to appear only once and not repeat after every command..

PS1 is not a "header" (such a thing doesn't even exist). It's the prompt.

.bashrc is executed every time you start an interactive prompt. Just add the commands to print your welcome message there.

EzioAuditore 04-03-2011 12:25 PM

Oh yeah yeah.. I meant the prompt... My bad..

Regarding the message, i added but it appears after every command.. I've posted my PS1 line in main post.. Can u post an edited version of it with the problem rectified?

MTK358 04-03-2011 12:39 PM

Quote:

Originally Posted by EzioAuditore (Post 4312456)
Regarding the message, i added but it appears after every command.. I've posted my PS1 line in main post.. Can u post an edited version of it with the problem rectified?

???????????????????????

The prompt is supposed to appear after every command, that's why it's called the prompt!

If you want a message to appear when you open a terminal, you DO NOT do it by modifying PS1!

EzioAuditore 04-03-2011 01:05 PM

Ok Ok.. So what should be edited to achieve that?

RockDoctor 04-03-2011 02:23 PM

If you're booting to the terminal, you might consider editing /etc/rc.local:
Code:

echo "Your prompt here"

MTK358 04-03-2011 02:57 PM

Quote:

Originally Posted by RockDoctor (Post 4312549)
If you're booting to the terminal, you might consider editing /etc/rc.local:
Code:

echo "Your prompt here"

That's not a prompt!

Also, I'd put it in .bashrc, that way it will work everywhere. In .bashrc, just add code that will print the message. For example:

Code:

echo "You will see this every time you open a terminal"
And I hope you do understand what a prompt is, right?

theNbomr 04-03-2011 03:26 PM

There are several levels at which messages can be emitted.
  • An echo command in /etc/rc.local, or any of the startup scripts in /etc/init.d will be executed at boot time.
  • A message echoed from /etc/bashrc (variations per distro) will be emitted whenever an interactive bash shell is started by anyone on that host.
  • A message in your $HOME/.bashrc will be emitted whenever you launch a new shell.
  • A message in $PS1 will be emitted each time a new commandline can accept user input (which is why it is called a prompt, I suppose).
  • The Message Of The Day (/etc/motd) will be displayed after a login.

--- rod.

EzioAuditore 04-03-2011 03:46 PM

Oh thanks for all your replies..
Its late night here... and also facing some boot problems..
I'll try these tomorrow and let you guys know..

RockDoctor 04-03-2011 07:01 PM

Quote:

Originally Posted by MTK358 (Post 4312568)
That's not a prompt!

Also, I'd put it in .bashrc, that way it will work everywhere. In .bashrc, just add code that will print the message. For example:

Code:

echo "You will see this every time you open a terminal"
And I hope you do understand what a prompt is, right?

It wasn't supposed to be a prompt (although that's what the original poster called it) - it's supposed to be a welcome message (I think) :) But, you're right, .bashrc would be a better place for it

EzioAuditore 04-04-2011 07:33 AM

Ok guys, that echo command did what I wanted. Now is there any way to have keywords like sudo, chmod etc to be in different color than the rest of the command?

MTK358 04-04-2011 08:10 AM

Quote:

Originally Posted by EzioAuditore (Post 4313233)
Ok guys, that echo command did what I wanted. Now is there any way to have keywords like sudo, chmod etc to be in different color than the rest of the command?

No.

EzioAuditore 04-04-2011 02:07 PM

Quote:

Originally Posted by MTK358 (Post 4313273)
No.

Okay! Thanks.


All times are GMT -5. The time now is 11:45 PM.