Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    PATH=/usr/local/fortran:$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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
"source" solves the problem. thanks –  DMF May 20 '12 at 17:07
    
@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
add comment

Put

PATH=/usr/local/fortran:$PATH
export PATH

in your .bash_profile file.

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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