4

I am new to ubuntu, and tried to use OpenFOAM Installation worked OK; after that I copy-pasted the very first example, worked also OK. but I cannot understand how. There are funny commands like:

mkdir -p $FOAM_RUN 

This creates the folder structure /home/username/OpenFOAM/username-2.3.1/run

Or

cp -r $FOAM_TUTORIALS $FOAM_RUN 

This copies the tutorials in the above mentioned folder

What does the sign $ do?

These commands work when copy-pasted, but I want understanding them and being able to use them later on.

8

The name of a variable is a placeholder for its value, the data it holds. Referencing (retrieving) its value is called variable substitution. The $ sign helps us to get the value.

Let us carefully distinguish between the name of a variable and its value. If variable1 is the name of a variable, then $variable1 is a reference to its value, the data item it contains, for example:

We define variable1 with a value 23:

$ variable1 = 23

To print the name of the variable (echo is just like a print function in the terminal):

$ echo variable1
variable1

To print the actual value saved in the variable

$ echo $variable1
23
  • 2
    Many thanks, I am a bit clever (or at least more informed:) than 3 h ago:) – GFelix Dec 15 '14 at 17:52
2

Variables in your shell are marked with a $. I assume a path has been stored as $FOAM_RUN. You can see all variables in your shell by running:

$ env
XDG_SESSION_ID=2
GDM_LANG=en_US.utf8
XDG_RUNTIME_DIR=/run/user/1000
WINDOWID=41943044
HOME=/home/orangetux
XDG_VTNR=7
SSH_AGENT_PID=1774
XDG_SEAT=seat0
COLORTERM=gnome-terminal
...

You can see the the value of a variable by printing it:

$ echo $HOME
/home/orangetux

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.