2

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?

0

2 Answers 2

6

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.

3
  • @DMF If you want it to stick for every terminal session, see my update to the answer.
    – slhck
    May 20, 2012 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, 2012 at 17:35
  • @DMF Alright. Make sure you accept Prince John Wesley's answer by clicking the checkmark next to it! :)
    – slhck
    May 20, 2012 at 17:41
1

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)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .