After I "source mpi.ksk", PATH is unchanged but LD_LIBRARY_PATH is there:

   $ print $LD_LIBRARY_PATH
   /usr/lib64/openmpi/lib/

Why does PATH loose its change?

---John

On Sat, Apr 13, 2013 at 11:31 AM, Seb <[email protected]> wrote:
> Le Sat, 13 Apr 2013 00:51:02 -0400
> John Chludzinski a écrit:
>
> Hi,
>
>> I have a file mpi.ksh
>>
>>    #!/bin/mksh
>>    export PATH=/lib64/openmpi/bin/:$PATH
>>    export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib/
>>    mpiexec -n 1 printenv | grep PATH
>>
>> When I execute ./mpi.ksh, I get:
>>
>>    
>> PATH=/lib64/openmpi/bin/:/sbin:/usr/lib64/qt-.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:.
>>    LD_LIBRARY_PATH=/usr/lib64/openmpi/lib/
>>
>> ... but after the script has execute and returned:
>>
>>    > print $PATH
>>    
>> /sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
>>    > print $LD_LIBRARY_PATH
>>
>> Both assignments are gone.  I tried:
>>    source mpi.ksh
>>
>>    > print $PATH
>>    
>> /sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
>>    > print $LD_LIBRARY_PATH
>>    /usr/lib64/openmpi/lib/
>>
>> This time the assignment to LD_LIBRARY_PATH is there but the
>> update/assignment to PATH is not.
>>
>> What's up?
>
> Your script is run as a distinct process and then inherits a *copy*
> of the environment of the process it is forked from. So, all the
> changes you make in your script only affect this copy, not the
> environment of the father-process.
>
> If you want to change the environment of the current shell process,
> you have to source your script:
>
>  . /mpi.ksh
>
> Then, all the commands are executed as if you had entered them
> manually in the current shell.
>
> ++
> Seb.

Reply via email to