I just upgraded to Lion and I am using bash for the first time (my previous experience is with csh and tcsh). I have encountered unexpected behavior. A simple example is:

  1. I create a file containing the following commands:

    echo PATH BEFORE is $PATH
    export PATH
    echo PATH AFTER is $PATH
  2. I open a terminal (in bash) and execute the file shown above. It echoes the expected result:

    PATH BEFORE is /usr/bin: ...
    PATH AFTER is /usr/local/fortran:/usr/bin ...
  3. I then type:

    echo $PATH

    and /usr/local/fortran is NOT part of the path. I assumed that the export command would make the PATH sticky. Can someone explain why this is not happening?


You need to source the file so that the exported variables are accessible to the current shell.

source script-file
echo $PATH

… or add the export command to one of bash's configuration files — In OS X, that'd typically be .bash_profile.

  • @DMF If you want it to stick for every terminal session, see my update to the answer.
    – slhck
    May 20 '12 at 17:09
  • This is for code that I am embedding in a GUI. I don't (and don't want to) alter things that .bash_profile. Instead, I want to execute that change in $PATH only for the present shell. So, the "source" approach solves the problem.
    – DMF
    May 20 '12 at 17:35
  • @DMF Alright. Make sure you accept Prince John Wesley's answer by clicking the checkmark next to it! :)
    – slhck
    May 20 '12 at 17:41


export PATH

in your .bash_profile file.

How do you execute the file containing the command ? Try sourceing it with source (man source)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.