CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Bugs

Kubuntu uses dash breaks All scripts in tutorials

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 30, 2008, 10:30
Default (K)ubuntu versions since Edgy,
  #1
Member
 
Graeme Cottrell
Join Date: Mar 2009
Posts: 30
Rep Power: 8
platopus is on a distinguished road
(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 is offline   Reply With Quote

Old   March 30, 2008, 11:09
Default A follow-up. I just found the
  #2
Member
 
Graeme Cottrell
Join Date: Mar 2009
Posts: 30
Rep Power: 8
platopus is on a distinguished road
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 is offline   Reply With Quote

Old   March 30, 2008, 15:06
Default More progress. I have a bas
  #3
Member
 
Graeme Cottrell
Join Date: Mar 2009
Posts: 30
Rep Power: 8
platopus is on a distinguished road
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 is offline   Reply With Quote

Old   March 30, 2008, 15:41
Default Added a brief reference to thi
  #4
Member
 
Graeme Cottrell
Join Date: Mar 2009
Posts: 30
Rep Power: 8
platopus is on a distinguished road
Added a brief reference to this in the wiki.

If anyone comes up with a better solution, please make youself heard.
platopus is offline   Reply With Quote

Old   March 31, 2008, 16:34
Default Strange, I built stock OF 1.4.
  #5
Senior Member
 
Srinath Madhavan (a.k.a pUl|)
Join Date: Mar 2009
Location: Edmonton, AB, Canada
Posts: 698
Rep Power: 12
msrinath80 is on a distinguished road
Strange, I built stock OF 1.4.1 on Gutsy and never faced any problems.
msrinath80 is offline   Reply With Quote

Old   March 31, 2008, 16:35
Default Oh, just noticed. You meant tu
  #6
Senior Member
 
Srinath Madhavan (a.k.a pUl|)
Join Date: Mar 2009
Location: Edmonton, AB, Canada
Posts: 698
Rep Power: 12
msrinath80 is on a distinguished road
Oh, just noticed. You meant tutorials. OK. That could be possible. I only run my own cases these days.
msrinath80 is offline   Reply With Quote

Old   April 1, 2008, 14:44
Default Hi Graeme, looks like you a
  #7
Super Moderator
 
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,416
Rep Power: 16
mattijs is on a distinguished road
Hi Graeme,

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

Old   April 15, 2008, 07:42
Default Hi, "similar" shell-thing in m
  #8
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 85
Rep Power: 8
wikstrom is on a distinguished road
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 is offline   Reply With Quote

Old   April 15, 2008, 07:52
Default Oh, seems only to be foamNew t
  #9
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 85
Rep Power: 8
wikstrom is on a distinguished road
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
wikstrom is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error running fluent 64 bit in kubuntu 8.1064-bit Anastasios Georgoulas FLUENT 20 September 8, 2011 07:20
ICEM CFD Scripts Vinod Dhiman Main CFD Forum 2 February 17, 2010 11:56
Installation on Kubuntu 710 sega Open Source Meshers: Gmsh, Netgen, CGNS, ... 0 September 20, 2008 11:04
How to use the Allrun Alltest scripts for the tutorials david_flo1 OpenFOAM 1 February 21, 2008 04:21


All times are GMT -4. The time now is 06:34.