LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 01-01-2003, 10:55 AM   #1
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Rep: Reputation: 15
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.
 
Old 01-01-2003, 11:04 AM   #2
jetfreggel
Member
 
Registered: May 2002
Posts: 172

Rep: Reputation: 30
do man bash
and then / ---> is the same as search
and type in PS1 which is your prompt
 
Old 01-01-2003, 11:45 AM   #3
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Original Poster
Rep: Reputation: 15
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?
 
Old 01-01-2003, 12:14 PM   #4
jetfreggel
Member
 
Registered: May 2002
Posts: 172

Rep: Reputation: 30
did you look at .bash_profile
did you export PS1
you can also do after the changes source filename containing PS1
line

good luck
 
Old 01-01-2003, 01:45 PM   #5
bvc
LQ Newbie
 
Registered: Nov 2002
Location: Houston, Texas
Distribution: LFS-4.0 and Mandrake 9.0
Posts: 7

Rep: Reputation: 0
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
Quote:
source ~/.bashrc
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/
 
Old 01-01-2003, 02:29 PM   #6
NSKL
Senior Member
 
Registered: Jan 2002
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207

Rep: Reputation: 46
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
 
Old 01-01-2003, 04:38 PM   #7
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Original Poster
Rep: Reputation: 15
Very cool. Thank You...
 
Old 01-01-2003, 05:59 PM   #8
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Original Poster
Rep: Reputation: 15
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.
 
Old 01-01-2003, 06:34 PM   #9
jetfreggel
Member
 
Registered: May 2002
Posts: 172

Rep: Reputation: 30
see man chmod
chmod 700 filename
or
chmod u+x filename
extensions are not important in linux
 
Old 01-01-2003, 09:31 PM   #10
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Original Poster
Rep: Reputation: 15
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?
 
Old 01-01-2003, 10:28 PM   #11
jetfreggel
Member
 
Registered: May 2002
Posts: 172

Rep: Reputation: 30
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
 
Old 01-01-2003, 11:45 PM   #12
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Original Poster
Rep: Reputation: 15
I am gonna stop worrying about the prompt for now, but that last example worked for me, Thanks...
 
Old 01-01-2003, 11:49 PM   #13
jetfreggel
Member
 
Registered: May 2002
Posts: 172

Rep: Reputation: 30
YOU;RE WELCOME AND DON'T GIVE THAT UP EASILY
IT IS NOT SO DIFFICULT
 
Old 01-02-2003, 03:40 AM   #14
NSKL
Senior Member
 
Registered: Jan 2002
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207

Rep: Reputation: 46
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
 
Old 01-02-2003, 10:14 AM   #15
kleptos
LQ Newbie
 
Registered: Jan 2003
Location: Boca Raton, FL
Distribution: Slackware
Posts: 22

Original Poster
Rep: Reputation: 15
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?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash prompt subG Slackware 6 01-18-2006 05:43 PM
customize bash kpachopoulos Linux - General 2 05-27-2005 03:50 PM
help with bash prompt everythingand2 Linux - Newbie 7 12-06-2003 05:28 PM
Bash Prompt mandraketux Mandriva 2 11-28-2003 11:05 PM
bash problem: no prompt xyfan Linux - General 6 11-25-2003 12:15 PM


All times are GMT -5. The time now is 10:18 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration