CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Bugs (http://www.cfd-online.com/Forums/openfoam-bugs/)
-   -   Kubuntu uses dash breaks All scripts in tutorials (http://www.cfd-online.com/Forums/openfoam-bugs/62488-kubuntu-uses-dash-breaks-all-scripts-tutorials.html)

platopus March 30, 2008 10:30

(K)ubuntu versions since Edgy,
 
(K)ubuntu versions since Edgy, including Gutsy, which I am using, use dash as the default shell:

graeme@graeme-vaio:/bin$ ls -l /bin/sh*
lrwxrwxrwx 1 root root 4 2007-10-31 05:02 /bin/sh -> dash
lrwxrwxrwx 1 root root 4 2007-10-31 05:02 /bin/sh.distrib -> bash
graeme@graeme-vaio:/bin$

I'm not sure what the symlink /bin/sh.distrib is used for.

This use of dash causes problems with Allrun, Allclean and other scripts in the tutorials directory tree.

Replacing the shebangs in the scripts with #!/bin/bash makes the problems seem to go away. I don't know exactly where they trip up, but here's an example of running Allrun in the icoFoam directory after a fresh install of the tutorials:

graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$ ./Allrun
Running blockMesh on cavity
Running icoFoam on cavity
Cloning cavityFine case from cavity
cp: cannot stat `cavity/{0,system,constant}': No such file or directory
sed: can't read cavityFine/constant/polyMesh/blockMeshDict: No such file or directory
mv: cannot move `temp.24790' to `cavityFine/constant/polyMesh/blockMeshDict': No such file or directory
sed: can't read cavityFine/system/controlDict: No such file or directory
mv: cannot move `temp.24790' to `cavityFine/system/controlDict': No such file or directory
Running blockMesh on cavityFine
Running mapFields from cavity to cavityFine
Running icoFoam on cavityFine
Running blockMesh on cavityGrade
Running mapFields from cavityFine to cavityGrade
Running icoFoam on cavityGrade
Cloning cavityHighRe case from cavity
cp: cannot stat `cavity/{0,system,constant}': No such file or directory
Setting cavityHighRe to generate a secondary vortex
sed: can't read cavityHighRe/system/controlDict: No such file or directory
mv: cannot move `temp.24790' to `cavityHighRe/system/controlDict': No such file or directory
sed: can't read cavityHighRe/constant/transportProperties: No such file or directory
mv: cannot move `temp.24790' to `cavityHighRe/constant/transportProperties': No such file or directory
Copying cavity/0* directory to cavityHighRe
Running blockMesh on cavityHighRe
Running icoFoam on cavityHighRe
Running blockMesh on cavityClipped
Running mapFields from cavity to cavityClipped
Running icoFoam on cavityClipped
fluentMeshToFoam: converting mesh elbow/elbow.msh
Running icoFoam on elbow
Running foamMeshToFluent on elbow
Running foamDataToFluent on elbow
graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$

then running Allclean:

graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$ ./Allclean
Cleaning cavity case of icoFoam application
./Allclean: 18: let: not found
./Allclean: 18: let: not found
./Allclean: 18: let: not found
./Allclean: 18: let: not found
./Allclean: 18: let: not found
... ad infinitum

Replacing the symlink at /bin/sh to point to bash seems to be an option, but I am reluctant to make such a system-wide change for the sake of OpenFOAM - I don't know what else might break. Replacing the shebangs in the scripts to use bash gives:

graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$ ./Allrun
Running blockMesh on cavity
Running icoFoam on cavity
Cloning cavityFine case from cavity
Running blockMesh on cavityFine
Running mapFields from cavity to cavityFine
Running icoFoam on cavityFine
Running blockMesh on cavityGrade
Running mapFields from cavityFine to cavityGrade
Running icoFoam on cavityGrade
Cloning cavityHighRe case from cavity
Setting cavityHighRe to generate a secondary vortex
Copying cavity/0* directory to cavityHighRe
Running blockMesh on cavityHighRe
Running icoFoam on cavityHighRe
Running blockMesh on cavityClipped
Running mapFields from cavity to cavityClipped
Running icoFoam on cavityClipped
fluentMeshToFoam: converting mesh elbow/elbow.msh
Running icoFoam on elbow
Running foamMeshToFluent on elbow
Running foamDataToFluent on elbow
graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$

and for Allclean:

graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$ ./Allclean
Cleaning cavity case of icoFoam application
Cleaning cavityGrade case of icoFoam application
Cleaning cavityClipped case of icoFoam application
Cleaning elbow case of icoFoam application
Removing cavityFine case of icoFoam application
Removing cavityHighRe case of icoFoam application
graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials/icoFoam$

I assume these are the correct outputs for these cases.

Perhaps the scripts aren't quite POSIX conformant, or perhaps dash has bugs - I don't know. I do know that the Ubuntu variants have a huge user base and some of those users are going to want to run OpenFOAM. Other novices are going to trip over this problem and not know what to do. I see no previous reference to this in the forums here.

Anyone got any comments or suggestions?

Someone like to whip up a quick script that will automate the changing of the shebangs?

platopus March 30, 2008 11:09

A follow-up. I just found the
 
A follow-up. I just found the tool checkbashisms (in the devscripts package) which reports on CleanFunctions thus:

graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials$ checkbashisms CleanFunctions
possible bashism in CleanFunctions line 57 (let ...):
let nZeros=nZeros+1
possible bashism in CleanFunctions line 59 (brace expansion):
rm -rf $1/{[1-9]*,-[1-9]*,log,log.*,log-*,logSummary.*,.fxLock,*.xml,ParaView*,paraFoam *,*.foam} > /dev/null 2>&1
possible bashism in CleanFunctions line 66 (brace expansion):
rm -rf $1/constant/polyMesh/{allOwner*,cell*,face*,meshModifiers*} \
possible bashism in CleanFunctions line 67 (brace expansion):
$1/constant/polyMesh/{owner*,neighbour*,point*,edge*} \
possible bashism in CleanFunctions line 92 (brace expansion):
rm -rf $1/{samples,sampleSurfaces} > /dev/null 2>&1
possible bashism in CleanFunctions line 97 (brace expansion):
rm -rf $1/0/{Ux,Uy,Uz} > /dev/null 2>&1
graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials$

and on RunFunctions like this:

graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials$ checkbashisms RunFunctions
possible bashism in RunFunctions line 77 (brace expansion):
cp -r $1/{0,system,constant} $2
graeme@graeme-vaio:~/OpenFOAM/graeme-1.4.1/run/tutorials$


The brace expansions may be easy enough to remove, but what about the let statement?
Is there a POSIX compliant way to do that sort of arithmetic?

platopus March 30, 2008 15:06

More progress. I have a bas
 
More progress.

I have a bash script, using find and sed, that replaces the shebangs with #!/bin/bash.

I'm calling it InitTuts, and the current version destroys any existing tutorial data that you've been working on, makes a new copy of the tutorials in the correct place, then systematically modifies the scripts. Create InitTuts in $HOME/OpenFOAM/${LOGNAME}-1.4.1/run, make it executable and then make sure you're not using the tutorial directories in any way, then just run it. YMMV.

#!/bin/bash
cd $HOME/OpenFOAM/${LOGNAME}-1.4.1/run

echo Removing existing tutorial data
rm -rf $HOME/OpenFOAM/${LOGNAME}-1.4.1/run/tutorials

echo Making a fresh copy of the tutorials from $WM_PROJECT_DIR/tutorials
cp -r $WM_PROJECT_DIR/tutorials $HOME/OpenFOAM/${LOGNAME}-1.4.1/run

scripts="Allclean Allrun Alltest CleanFunctions RunFunctions"

echo Processing shebangs in scripts to explicitly reference /bin/bash
for script in $scripts
do
echo processing for $script scripts
find $HOME/OpenFOAM/${LOGNAME}-1.4.1/run/tutorials \
-name $script -execdir sed -i s/"#!\/bin\/sh"/"#!\/bin\/bash"/ $script \;

done
echo done.

platopus March 30, 2008 15:41

Added a brief reference to thi
 
Added a brief reference to this in the wiki.

If anyone comes up with a better solution, please make youself heard.

msrinath80 March 31, 2008 16:34

Strange, I built stock OF 1.4.
 
Strange, I built stock OF 1.4.1 on Gutsy and never faced any problems.

msrinath80 March 31, 2008 16:35

Oh, just noticed. You meant tu
 
Oh, just noticed. You meant tutorials. OK. That could be possible. I only run my own cases these days.

mattijs April 1, 2008 14:44

Hi Graeme, looks like you a
 
Hi Graeme,

looks like you are right - we seem to be using bash extensions instead of pure Posix. I'll have a look.

wikstrom April 15, 2008 07:42

Hi, "similar" shell-thing in m
 
Hi, "similar" shell-thing in most csh scripts on Ubuntu:

Description:
Running a csh script including e.g. a 'number of args'-test like in foamNew:
if ( $# != 2 ) then
result in
Illegal variable name


Solver/Application:
csh-scripts in $WM_PROJECT_DIR/bin/

Source file:
E.G. $WM_PROJECT_DIR/bin/foamNew

Testcase:
any

Platform:
Ubuntu Linux 8.*

Version:
1.4.1

Notes:
Easily corrected by changing $# to $* or $argv[*]


cd $WM_PROJECT_DIR/bin
for file in $(egrep -l "^#\!.*csh"; do
echo $file
sed -i_bak -e 's/$#/$argv[\*]/g' $file
done


wikstrom April 15, 2008 07:52

Oh, seems only to be foamNew t
 
Oh, seems only to be foamNew that is affected by this, since most other scripts ar sh and not csh.

and in the "fix" above a parenthesis is missing. Use only:

sed -i_bak -e 's/$#/$argv[\*]/g' foamNew


All times are GMT -4. The time now is 03:44.