Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > How to change bash environment?

How to change bash environment?
Thread Tools
Junior Member
Join Date: Aug 2002
Status: Offline
Reply With Quote
Dec 5, 2003, 05:59 PM
 
I just changed tsch to bash in Netinfo. Restart. Everything is OK.

Now I want to change the prompt since it is too long (IP path and login name ) But I cannot find .bash_profile. So I create it. However the prompt is unchanged.

Which file I need to modify?
     
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Dec 6, 2003, 12:19 AM
 
From the bash man page:

When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists. This
may be inhibited by using the --norc option. The --rcfile file option
will force bash to read and execute commands from file instead of
~/.bashrc.
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Dec 6, 2003, 11:00 AM
 
For all sorts of bash prompt tips and tricks see:

http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html
-DU-...etc...
     
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Dec 6, 2003, 03:35 PM
 
the important bit to remember from the manual is "therefore it should be stressed that PS1=..blah.. should be in .bashrc and not .profile."

This is the one I use (nice and simple):

PS1="\t \w \u:>"
     
Dedicated MacNNer
Join Date: Jul 2002
Location: Boston, MA
Status: Offline
Reply With Quote
Dec 10, 2003, 07:27 PM
 
Originally posted by barbarian:
the important bit to remember from the manual is "therefore it should be stressed that PS1=..blah.. should be in .bashrc and not .profile."

This is the one I use (nice and simple):

PS1="\t \w \u:>"
Just out of curiosity, why is it that ~/.profile should not be used for PS1 variables? I have

PS1="\u@\h> "
export PS1


in my ~/.profile and it has not caused any problems.

I keep all my environment variables in ~/.profile, like CVSROOT, CVS_RSH, various aliases etc.
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Dec 10, 2003, 08:07 PM
 
My bash prompt (which is in the .bashrc on my system):

Code:
export PS1="[\u@\h \w] "
If you want a fancy color one, you could use this:

Code:
export PS1="\[\e[1;37m\][\[\e[1;33m\]\u@\h \e[1;32m\]\w\[\e[1;37m\]]\[\e[0;37m\] "
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status: Offline
Reply With Quote
Dec 10, 2003, 09:59 PM
 
   My prompt is set in a separate script, which is available at http://kerbaugh.uncfsu.edu/prompt.tgz. It's multi-colored, displays the history number, which changes color depending on the success of the last command, and when the last command fails, it displays the error code. The best feature is that it displays the path to the PWD. It truncates the path but not based on string length. It displays the last three directories in the path. You can change this number by setting the variable "LEVEL" in the script.

   This last feature is builtin to zsh and tcsh. To me, bash is the ultimate scripting shell but not the best interactive shell. I have config scripts for zsh posted at the same site should you feel like trying a better shell
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:57 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2