Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
01-01-2003, 09:55 AM
|
#1
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Rep:
|
Customize BASH Prompt
I'm new to linux (kinda sorta) and i spend alot of time at the bash prompt. I thought i saw a few pages (a long time ago) that showed how to make custom BASH prompts. With color, and different information and such, not just the standard username@host:~$ prompt. Any and all help would be greatly appreciated.
|
|
|
01-01-2003, 10:04 AM
|
#2
|
Member
Registered: May 2002
Posts: 172
Rep:
|
do man bash
and then / ---> is the same as search
and type in PS1 which is your prompt
|
|
|
01-01-2003, 10:45 AM
|
#3
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Original Poster
Rep:
|
Hmmm, maybe i messed something up but i dont have a .bashrc in my directory. So i created one, and rebooted, and my prompt didnt change to the one in my .bashrc file. Does Slackware use a different rc file or do i need to do something else?
|
|
|
01-01-2003, 11:14 AM
|
#4
|
Member
Registered: May 2002
Posts: 172
Rep:
|
did you look at .bash_profile
did you export PS1
you can also do after the changes source filename containing PS1
line
good luck
|
|
|
01-01-2003, 12:45 PM
|
#5
|
LQ Newbie
Registered: Nov 2002
Location: Houston, Texas
Distribution: LFS-4.0 and Mandrake 9.0
Posts: 7
Rep:
|
In mandrake9.0 the default ~/.bashrc says
Quote:
# .bashrc
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
|
I put this in ~/.bash_profile
this is my prompt, at the bottom of ~/.bashrc
Quote:
if [ "$TERM" = "linux" ]
then
#we're on the system console or maybe telnetting in
export PS1="[\u@\h \W]\$"
else
#we're not on the console, assume an xterm
export PS1="\[\e]2;\w\a\e[0;33m\]{\[\e[1;30m\]\u \@ \W\[\e[0;33m\]}\[\e[1;30m\]>\e[0m"
fi
|
http://www.linuxlookup.com/html/arti...m-prompts.html
http://www-106.ibm.com/developerwork.../l-tip-prompt/
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/
|
|
|
01-01-2003, 01:29 PM
|
#6
|
Senior Member
Registered: Jan 2002
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207
Rep:
|
In slack you need to create a script make it executabel and stick into /etc/profile.d. It will get executed every time bash starts. Here's mine for reference:
#!/bin/bash
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
PURPLE="\[\033[0;35m\]"
CYAN="\[\033[0;36m\]"
YELLOW="\[\033[0;33m\]"
NONE="\[\033[0m\]"
# Things BASH understands:
# \a an ASCII bell character (07)
# \d the date in "Weekday Month Date" format
# \e an ASCII escape character (033)
# \h the hostname up to the first `.'
# \H the hostname
# \j the number of jobs currently managed by the shell
# \l the basename of the shell's terminal device
# \n newline
# \r carriage return
# \t the current time in 24-hour HH:MM:SS format
# \T the current time in 12-hour HH:MM:SS format
# \@ the current time in 12-hour am/pm format
# \u the username of the current user
# \v the version of bash (e.g., 2.00)
# \V the release of bash, version + patchlevel
# \w the current working directory
# \W the basename of the current working dir
# \! the history number of this command
# \# the command number of this command
# \$ if the effective UID is 0, a #, otherwise a $
# \\ a backslash
#
if
[ "$UID" = "0" ];
then
# I am root
GREEN="\[\033[0;33m\]"
CYAN="\[\033[0;31m\]"
fi
PS1="$GREEN|:-($YELLOW\d \t$GREEN)$YELLOW-$GREEN($CYAN\u$GREEN@$CYAN\h:$GREEN\w$GREEN)$CYAN\$$NONE "
HTH
-NSKL
|
|
|
01-01-2003, 03:38 PM
|
#7
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Original Poster
Rep:
|
Very cool. Thank You...
|
|
|
01-01-2003, 04:59 PM
|
#8
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Original Poster
Rep:
|
Quote:
create a script make it executabel and stick into /etc/profile.d.
|
Do i have to name it anything special? I am not sure of all the file types and extensions yet. How do i make it executable?
Thanks for the help, i really appreciate it.
|
|
|
01-01-2003, 05:34 PM
|
#9
|
Member
Registered: May 2002
Posts: 172
Rep:
|
see man chmod
chmod 700 filename
or
chmod u+x filename
extensions are not important in linux
|
|
|
01-01-2003, 08:31 PM
|
#10
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Original Poster
Rep:
|
Ok, i am about to give up. I tried to create the executable and it only works if i use the root account. Then i get the following errors....
bash: RED: command not found
bash: GREEN: command not found
etc...
Any ideas?
|
|
|
01-01-2003, 09:28 PM
|
#11
|
Member
Registered: May 2002
Posts: 172
Rep:
|
forget about the colors you can try that later
put this in your .bash_profile
PS1="\u@\h\s$"
export PS1
this only works in the .bash_profile for the user that you are logged in at
if you changes skel dir(which is on slack i don;t know)
and if you than add a new user he will have the same prompt
also look at the linux document project for how to's
http://www.ibiblio.org/pub/Linux/doc...r-formats/pdf/
and look for bash prompt howto
|
|
|
01-01-2003, 10:45 PM
|
#12
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Original Poster
Rep:
|
I am gonna stop worrying about the prompt for now, but that last example worked for me, Thanks...
|
|
|
01-01-2003, 10:49 PM
|
#13
|
Member
Registered: May 2002
Posts: 172
Rep:
|
YOU;RE WELCOME AND DON'T GIVE THAT UP EASILY
IT IS NOT SO DIFFICULT
|
|
|
01-02-2003, 02:40 AM
|
#14
|
Senior Member
Registered: Jan 2002
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207
Rep:
|
If you just opied and pasted my script, that might be the problem, some characters might have shifted.
If you took time to analyze the script you would see all the color variables are defines at the beggining giving them ASCII color codes, so it must be your error. Try to copy the script again, or type it out in gedit (you can ignore lines beggining with # they are comments) then as root save it to /etc/profile.d/shell.sh
then chmod a+x /etc/profile.d/shell.sh and start a new xterm and you should get a colored prompt. Later you can edit my script to put any info you want and any colors. Also read the bash prmpt howto or the bash customization how to from tldp.org or google.
HTH
-NSKL
|
|
|
01-02-2003, 09:14 AM
|
#15
|
LQ Newbie
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22
Original Poster
Rep:
|
I am able to get the prompts and all that, just not the colors. I guess i didnt mention i am straight in the shell. Not going through x, does that matter?
|
|
|
All times are GMT -5. The time now is 03:55 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|