Tuesday, April 12, 2022

[SOLVED] creating dir with mkdir in debian

Issue

I am trying to create a directory using mkdir in Debian but the problem is that the directory is created in the root directory. The problem comes trying to install OpenFOAM and I suspect that it is because "$" is used to create it.

Following the instructions in the OpenFOAM web site, it says to create a folder

$HOME/OpenFOAM/user-2.2.1

and then, to create within a folder called "run" using:

mkdir -p /FOAM_RUN

the problem is that the final directory (run) should have the following form:

/home/OpenFOAM/user-2.2.1/run

but using Debian I cannot create a dir with "sudo", so I have to do it as root and when I go inside the directory /home/OpenFOAM/user-2.2.1 and I do mkdir -p /FOAM_RUN , then the created folder is:

/root/OpenFOAM/root-2.2.1/run

and I need it to be created in the /home directory and not in the /root directory. I had created the folder just using

mkdir -p /home/OpenFOAM/user-2.2.1/run

but when I try to execute the OpenFOAM orders it doesn't work.

My questions are:

Why should mkdir $FOAM_RUN create the run directory and if I do it just as "mkdir run", it doesn't work?

Why is the "$" symbol there when I use mkdir? I was searching for it and (for example) the mkdir manual says nothing about it.

Excuse me, I am not an expert in Linux.


Solution

The instructions are fairly straightforward, but you seem to have missed one of the notes. To reiterate a point they are making, you need to source ~/.bashrc after updating it. Then if you echo "$FOAM_RUN" you should see that this variable is now set to something like /home/luser/OpenFOAM/luser-2.2.1/run.

If you prefer to override it by hand, and assuming your user name is luser and your OpenFOAM version is 2.2.1, do this:

FOAM_RUN=$HOME/OpenFOAM/$USER-2.2.1/run
mkdir -p "$FOAM_RUN" # Note pedantic quoting

But if your .bashrc contains the code they instruct you to add, this should not be necessary.



Answered By - tripleee
Answer Checked By - Willingham (WPSolving Volunteer)