Click to See Complete Forum and Search --> : Noob needs help with ~/.bash_profile


balford
07-11-2002, 09:39 AM
hey all,
I'm a newbie... and taking my first attempts at bash scripting. I was reading the NHF on bash scripting... I got a feel for some of the commands. I can copy/move/create/delete directories and do the ls commands and all that stuff we know and love, but i think i wanna move on.

I checked out my ~/.bash_profile so I could edit the PS1 variable.
To my understanding, the PS1 (Variable?) is what controls what the command line in a terminal looks like.

My first problem is that no where in the ~/.bash_profile can i find "PS1". So I tried adding the following in hopes to add the current time to my command line...:

PS1="[t u@\h \w]\$"

...but nothing happened. I reset my terminal after saving the file and still, nothin' happened.

Do I need to reset my comp or simply log off and log back in again?

I was also wondering... if 'PS1' is a "variable"?
If this is the case... do i need to add the line...:

export PS1

...after my previous line of code?

Thanks for the help!:D

-------------------------------------------
also... i'm not a huge programmer or anything... i mostly use my computer for music and video games. Are there any other neat little things and tricks I can do in a terminal that will be useful for me?? I'd love to learn... I really hate the idea of going back to windows, but when i turn on linux, I feel like i sit there and just listen to music. :( What can i do in it?

balford
07-11-2002, 09:42 AM
let me correct myself:

I was entering:

PS1="[\t \u@\h \w]\$"

I'm pretty sure that was correct.

Alex Cavnar, aka alc6379
07-13-2002, 03:04 AM
Three things:

1.) I think you do have to export PS1.
2.) PS1 is a variable.
3.) You may need to also put the PS1 variable in ~/.bashrc ; if you want the prompt to show up in a terminal window (which is a non-login shell, BTW), you need to use ~/.bashrc instead of ~/.bash_profile.

(As a side note, .bash_profile is for login shells. .bashrc is for non-login shells, such as xterms)

alfalfa
07-20-2002, 03:23 AM
Here's my crazy prompt that changes color if you've su'ed to root. It's all encapsulated within a function, so it's a little more than what you're asking, but you should export PS1. Here's what I've got as it appears in my .bashrc:

myprompt ()
{
local GREEN="\[\e[0;32m\]"
local WHITE="\[\e[0;37m\]"
local NOCLR="\[\e[0;0m\]"
local RED="\[\e[0;31m\]"
local BLUE="\[\e[0;34m\]"
local NOCLR="\[\e[0;0m\]"
local RED="\[\e[0;31m\]"
local BLUE="\[\e[0;34m\]"
local CYAN="\[\e[0;36m\]"
local VIOLET="\[\e[0;35m\]"
if [ "$UID" = "0" ]; # I am root
then
echo ""
echo "CHEATS ENABLED"
export PS1="\[\e]0;\u \d (\l)\a$GREEN{$RED\@ \w$GREEN}# $NOCLR"
else # I'm not root
export PS1="\[\e]0;\u \d (\l)\a$GREEN{$WHITE\@ \w$GREEN}$BLUE$sevDshlvl$GREEN%
$NOCLR"
fi
}

myprompt

BTW, if you change some of those zeros to ones, you'll get the bold bright colors.