Incorrect duplicate running of custom scripts
When running a custom script I see the script is run twice. I traced the issue and have a fix.
First, to reproduce the issue:
echo "echo 'running'" > test.sh
chmod a+x test.sh
openfoam-docker -c './test.sh'
What you see is the script is run twice.
The issue is this this line in /openfoam/run
# Preserve arguments when sourcing
if [ -f /openfoam/profile.rc ]
then . /openfoam/profile.rc '' || true
fi
Passing ''
when sourcing the script should override $@
to make it empty but this is a bash-specific feature. Since /openfoam/run
has the she-bang line of:
#!/bin/sh
Which is actually running dash
.
This means that the scripts passed into openfoam-docker
are passed into /openfoam/profile.rc
which quite far down the chain runs the test.sh
script. This seems to be how OpenFOAM loads third party scripts.
The fix I have locally is to change the she-bang line in /openfoam/run
to be /bin/bash
explicitly.