Modify Path

Hi,

This is certainly a simple question, but I have yet to receive sufficient info concerning it. I am using BASH on a Powerbook G4 running Leopard.

  • I would like to permanently add a directory to my path. How do I do this?

  • I understand that I can view my path by: echo $PATH. Is there a file where the path is displayed as well.

Thank you very much for any help.

Mike

look for file named .bash_profile in your home directory. in this file, add a line similar to:

export PATH=$PATH:/my/dir/path

Hi Yogesh,

I appreciate your help. Perhaps you can clear up one other path related issue.

  • Why modify the .bash_profile instead of the .bashrc?

  • Like I said I am using BASH on a Mac running Leopard. For the most part I use Terminal for my command line related work. However, sometimes I use X11 as well. I noticed that when i typed "echo $PATH" in a Terminal shell it returned a different series of directories than when I did the same in an X11 shell. I believe this is because those two programs check different environment files. Is that correct?

A user in a different forum suggested that I modify my .bash_profile and .bashrc files. Can you tell what exactly is going on? Here are the contents:

#####
.bash_profile:
if [ -f ~/.aliases ]; then
. ~/.aliases
fi

ulimit -Ss unlimited
source /Users/msb65/seadas5.2/config/seadas.env
#####

#####
.bashrc:

if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
#####

On your system there seems to be no difference between the two; one always sources the other if it exists. On my system, .bashrc is always sourced when I login, but .bash_profile is skipped for noninteractive shells.

Maybe. I've noticed that Apple sometimes customizes these things in odd ways.

Please use code tags for code. like [ code ] asdf [ /code ] except without the extra spaces.

# Checks if the ~/.aliases file exists;  if it does, sources it.
if [ -f ~/.aliases ]; then
. ~/.aliases
fi

# Something to do with file size limits.  Mine doesn't have -Ss, so see
# 'man ulimit' on your system..
ulimit -Ss unlimited

# Includes some mac-specific environment variables, perhaps
source /Users/msb65/seadas5.2/config/seadas.env
# If .bash_profile exists, source it.
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi

upon the start of a login shell, the bash will consult the below files in this order:

  1. /etc/profile
  2. ~.bash_profile
  3. ~.bash_login
  4. ~.profile
    when you start a nonlogin shell, bash consults only ~bashrc.

so there is a difference between them. however, thats not to say osx is different. i'm not sure about this. this is more typical of linux/solaris.