5

I am trying to install PETSc on my Ubuntu laptop. The first step of the installation is to invoke the following commands in the top level directory of the PETSc directory in the terminal.

export PETSC_DIR=$PWD
./config/configure.py --with-cc=gcc --with-fc=gfortran --download-f-blas-lapack=1 --download-mpich=1
make all test

Question 1: Should I actually enter in the word 'PWD' or the address of the top level PETSc directory?

Question 2: What I wanted to understand what the export keyword does in general and in particular what it does in the example. I have looked at some references on the export keyword and all of them did not really explain clearly. Probably I have been looking in the wrong places.

I have never done any shell scripting so a detailed answer would be very helpful...Thank you so much!!

1 Answer 1

7

All export does is make the value of an environment variable available to child processes.

In this case, they're assuming that you're in the top level directory of the PETSc directory. So using $PWD (print working directory) is just a shortcut so you don't have to type out the path. The effect should be identical:

[jm72@localhost PETSc_1_1_1_1]$ pwd
/home/jm72/soft/PETSc_1_1_1_1
[jm72@localhost PETSc_1_1_1_1]$ export PETSC_DIR=$PWD
[jm72@localhost PETSc_1_1_1_1]$ echo $PETSC_DIR
/home/jm72/soft/PETSc_1_1_1_1
[jm72@localhost PETSc_1_1_1_1]$ export PETSC_DIR=/home/jm72/soft/PETSC_1_1_1_1
[jm72@localhost PETSc_1_1_1_1]$ echo $PETSC_DIR
/home/jm72/soft/PETSC_1_1_1_1
Sign up to request clarification or add additional context in comments.

9 Comments

export doesn't set an environment variable, it marks it for exporting into child processes. FOO=BAR sets variable $FOO but does not export it to child processes, and export FOO marks $FOO for export without altering the value of it. export FOO=BAR is an alias for FOO=BAR; export FOO.
Yes, that's true. It was clear the OP was coming from the position of a beginner so I didn't want to make the explanation too complicated, but I've edited my answer to better reflect reality.
Ahhh thank you Adam and Jacob! That helped a lot! But I don't get what Adam says about child processes. What is a process? Is it one single session between opening and closing my gnome-terminal?
Also once we export a variable in one gnome-terminal session, then close the terminal and open it again, can we use the same environmental variables we defined in the previous session?
Try using the command pstree; it shows a list of running processes and their parent-child relationships.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.