3

This is my first post. I wanted to ask for any idea so to solve my problem. I am using Ubuntu 12.04 LTS, and my purpose is to use OpenFoam CFD software.

I am trying to execute an script called Allrun that corresponds to a tutorial. I am using the sudo command like this.

sudo ./Allrun

then it asks for my password and after introducing it, it suddenly appears a message saying:

./Allrun: 5: .: Can't open /bin/tools/RunFunctions

This path appeares at line 5 as sourced in the script, so like:

. $WM_PROJECT_DIR/bin/tools/RunFunctions

being $WM_PROJECT_DIR a variable defined in opt/openfoam22/etc/bashrc and pointing the directory:

$WM_PROJECT_DIR= /opt/openfoam222

(this bashrc is at the same time sourced in ~/.bashrc file, and I can use the variable in the terminal, so I assume it is allright sourced)

I have tried also to chmod the RunFunctions file with rwx permissions, and veryfied with "ls -la" that its permissions changed (they did), but didn't solve anything.

I am new in linux, and any help will be great, thanks in advance.

1 Answer 1

0

It seems that at the point of execution, the variable is not defined; the script search for a file /bin/tools/RunFunctions/, not /opt/openfoam222/bin/tools/RunFunctions.

Notice that non-interactive shells does not load .bashrc by default, so the fact that the variable is defined when you use it in interactive is not a proof. Even if you are running the script from you shell, the variables are not exported to sub-shell by default, they need to be declared export to do that.

Try to add a line like

echo "DEBUG variable is $WM_PROJECT_DIR"

before the failing line in ./Allrun and check the output. If this is the problem, you should explicitly source the file in your script. Or add an

export WM_PROJECT_DIR 

to pass it to subshells.

Added (after comments). Notice that you shouldn't explicitly source your .bashrc in your .profile (they have different meaning and the shell sources them in different occasions, see for example here.)

Scripts (non-interactive) should never rely on your login shell to run. If they need specific files/definitions, the should source them explicitly. For what you know, it could be called even from a different type of shell or from no shell at all.

4
  • I have tried to 'export' the variable within the script and it gets it and uses it alright! -great. Now what I see is that the script fails because the source has not been 'loaded'. My ~/.profile sources my ~/.bashrc, which sources the /opt/openfoam222/etc/bashrc I find there an odd variable definition such as: foamInstall=/opt : ${FOAM_INST_DIR:=$foamInstall}; export FOAM_INST_DIR (note the ": " before the $) and few lines further... export WM_PROJECT_INST_DIR=$FOAM_INST_DIR export WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/openfoam222 Any idea to source all this properly?
    – Danubi
    Nov 22, 2013 at 12:18
  • I am a little bit confused.
    – Danubi
    Nov 24, 2013 at 19:19
  • My .profile came from ubuntu12.04 written by default (I haven't touched it). It sources my ~/.bashrc by the following: # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi Furthermore I found in the OpenFoam 'Installation Guide' (openfoam.org/download/ubuntu.php) the step that asks for sourcing the /opt/openfoam222/etc/bashrc within the ~/.bashrc file. I have tried different tutorials and I get the same error everywhere.
    – Danubi
    Nov 24, 2013 at 19:35
  • I have just realized that I don't have my $HOME/bin directory (doesn't exist). I don't know if this might influence in anyway, I guess it doesn't, but still; it is not in my $PATH
    – Danubi
    Nov 24, 2013 at 20:01

You must log in to answer this question.

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