diff --git a/bin/foamDistccd b/bin/foamDistccd
index 38bfd05c3c99c601f6af1a3d63683a2059f0f6d7..94a42f6637c4621df8643bd4671e8c01a44f293f 100755
--- a/bin/foamDistccd
+++ b/bin/foamDistccd
@@ -34,31 +34,31 @@
 #
 #------------------------------------------------------------------------------
 
-printUsage()
+usage()
 {
-    echo "Usage : `basename $0` start|stop|list"
+    echo "Usage : ${0##*/} start|stop|list"
     echo ""
+    exit 1
 }
 
 RSH='ssh'
 
-if [ ! "$DISTCC_HOSTS" ]; then
-    echo "`basename $0`: variable DISTCC_HOSTS not set."
-    echo "`basename $0`: please set DISTCC_HOSTS to the list of hosts to use."
-    echo "`basename $0`: the format is host1:port host2:port host3:port etc."
-    echo ""
-
-    exit 1
-fi
+if [ ! "$DISTCC_HOSTS" ]
+then
+    echo "${0##*/} Warnings"
+    echo "    variable DISTCC_HOSTS not set."
+    echo "    please set DISTCC_HOSTS to the list of hosts to use."
+    echo "    the format is host1:port host2:port host3:port etc."
+    echo
 
-if [ $# -ne 1 ]; then
-    printUsage
     exit 1
 fi
 
+[ $# -eq 1 ] || usage
 
-if [ "$1" = 'start' ]; then
 
+case "$1" in
+start)
     grep -v '^#' /etc/hosts | awk '{print $1, $2 " "}' > ~/filteredHosts.txt
 
     allowIPS=''
@@ -66,7 +66,8 @@ if [ "$1" = 'start' ]; then
     do
         machine=`echo "$host" | awk -F: '{print $1}'`
         iptest=`echo "$machine" | sed -e 's/[0-9.]//g'`
-        if [ ! "$iptest" ]; then
+        if [ ! "$iptest" ]
+        then
             # address only contained 0-9 and '.'. Probably ip address.
             ip=$machine
         else
@@ -74,7 +75,8 @@ if [ "$1" = 'start' ]; then
             ip=`egrep " $machine " ~/filteredHosts.txt | awk '{print $1}'`
         fi
 
-        if [ ! "$ip" ]; then
+        if [ ! "$ip" ]
+        then
             echo "$0 : host specifier $host either is not an ip address or cannot be found in /etc/hosts."
             echo "$0 : Exiting."
             exit 1
@@ -92,7 +94,8 @@ if [ "$1" = 'start' ]; then
         machine=`echo "$host" | awk -F: '{print $1}'`
         port=`echo "$host" | awk -F: '{print $2}'`
 
-        if [ "$machine" -a "$port" ]; then
+        if [ "$machine" -a "$port" ]
+        then
             #echo "Machine:$machine  port:$port"
             echo "distccd --daemon $allowIPS --port $port"' --jobs `egrep "^processor" /proc/cpuinfo | wc -l`'
             $RSH $machine "distccd --verbose --daemon $allowIPS --port $port"' --jobs `egrep "^processor" /proc/cpuinfo | wc -l`'
@@ -102,9 +105,9 @@ if [ "$1" = 'start' ]; then
             exit 1
         fi
     done
+    ;;
 
-elif [ "$1" = 'stop' ]; then
-
+stop)
     for host in $DISTCC_HOSTS
     do
         echo ""
@@ -114,10 +117,9 @@ elif [ "$1" = 'stop' ]; then
 
         $RSH $machine killall distccd
     done
+    ;;
 
-
-elif [ "$1" = 'list' ]; then
-
+list)
     for host in $DISTCC_HOSTS
     do
         echo ""
@@ -127,12 +129,11 @@ elif [ "$1" = 'list' ]; then
 
         $RSH $machine "ps -ef | grep distccd | grep -v grep"
     done
+    ;;
 
-else
-
-    printUsage
-    exit 1
-
-fi
+*)
+    usage
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/bin/foamEbrowse b/bin/foamEbrowse
index b62137615097ba18e007ae624331633220b81a77..9e1cac582792c79996310ce0ad9d08dd2a454361 100755
--- a/bin/foamEbrowse
+++ b/bin/foamEbrowse
@@ -32,12 +32,13 @@
 #------------------------------------------------------------------------------
 sourcesFile=${TMPDIR:-/tmp}/sourcesFile.$$
 
-if [ $# -ne 0 ]; then
-   echo "Usage : ${0##*/}"
-   echo ""
-   echo "Build the Ebrowse dadbase for all the .H and .C files"
-   echo ""
-   exit 1
+if [ $# -ne 0 ]
+then
+    echo "Usage : ${0##*/}"
+    echo ""
+    echo "Build the Ebrowse database for all the .H and .C files"
+    echo ""
+    exit 1
 fi
 
 # Clean up on termination and on Ctrl-C
diff --git a/bin/tools/CleanFunctions b/bin/tools/CleanFunctions
index d1a29b464c6993a0762bb4535935511c2647dbb1..096774bc721877f7e80ae8193375a617971eecb6 100644
--- a/bin/tools/CleanFunctions
+++ b/bin/tools/CleanFunctions
@@ -29,13 +29,14 @@
 #
 #------------------------------------------------------------------------------
 
-#cleanTimeDirectories ()
+#cleanTimeDirectories()
 #{
 #    echo "Cleaning $case case of $application application"
 #    TIME_DIRS=`foamInfoExec . $1 -times | sed '1,/constant/d'`
 #    for T in $TIME_DIRS
 #    do
-#        if [ $T != "0" ] ; then
+#        if [ $T != "0" ]
+#        then
 #            echo "Deleting directory $T"
 #            rm -rf ${T} > /dev/null 2>&1
 #        fi
@@ -43,12 +44,13 @@
 #    rm -rf {log,log.*,log-*,logSummary.*,.fxLock,*.xml,ParaView*,paraFoam*,*.OpenFOAM} > /dev/null 2>&1
 #}
 
-cleanTimeDirectories ()
+cleanTimeDirectories()
 {
     echo "Cleaning $PWD case"
     nZeros=0
     zeros=""
-    while [ $nZeros -lt 8 ] ; do
+    while [ $nZeros -lt 8 ]
+    do
         timeDir="0.${zeros}[1-9]*"
         rm -rf ${timeDir} > /dev/null 2>&1
         rm -rf ./-${timeDir} > /dev/null 2>&1
@@ -58,7 +60,7 @@ cleanTimeDirectories ()
     rm -rf ./{[1-9]*,-[1-9]*,log,log.*,log-*,logSummary.*,.fxLock,*.xml,ParaView*,paraFoam*,*.OpenFOAM} > /dev/null 2>&1
 }
 
-cleanCase ()
+cleanCase()
 {
     cleanTimeDirectories
     rm -rf processor* > /dev/null 2>&1
@@ -82,23 +84,23 @@ cleanCase ()
     done
 }
 
-removeCase ()
+removeCase()
 {
     echo "Removing $case case"
     rm -rf $1
 }
 
-cleanSamples ()
+cleanSamples()
 {
     rm -rf {sets,samples,sampleSurfaces} > /dev/null 2>&1
 }
 
-cleanUcomponents ()
+cleanUcomponents()
 {
     rm -rf 0/{Ux,Uy,Uz} > /dev/null 2>&1
 }
 
-cleanApplication ()
+cleanApplication()
 {
     echo "Cleaning $PWD application"
     wclean
diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions
index 9e5f412fe23b8ce9cb30058f152f92bb954ed368..800c48e4f2df5c4f7b410bcd660dcb95f408ce44 100644
--- a/bin/tools/RunFunctions
+++ b/bin/tools/RunFunctions
@@ -29,17 +29,19 @@
 #
 #------------------------------------------------------------------------------
 
-getApplication ()
+getApplication()
 {
     grep application system/controlDict | sed "s/application *\([a-zA-Z]*\);/\1/"
 }
 
-runApplication ()
+runApplication()
 {
-    APP_RUN=$1; shift
+    APP_RUN=$1
+    shift
     APP_NAME=${APP_RUN##*/}
 
-    if [ -f log.$APP_NAME ] ; then
+    if [ -f log.$APP_NAME ]
+    then
         echo "$APP_NAME already run on $PWD: remove log file to run"
     else
         echo "Running $APP_RUN on $PWD"
@@ -47,11 +49,13 @@ runApplication ()
     fi
 }
 
-runParallel ()
+runParallel()
 {
-    APP_RUN=$1; shift
+    APP_RUN=$1
+    shift
 
-    if [ -f $log.$APP_RUN ] ; then
+    if [ -f $log.$APP_RUN ]
+    then
         echo "$APP_RUN already run on $PWD: remove log file to run"
     else
         echo "Running $APP_RUN in parallel on $PWD using $1 processes"
@@ -59,15 +63,16 @@ runParallel ()
     fi
 }
 
-compileApplication ()
+compileApplication()
 {
     echo "Compiling $1 application"
     wmake $1
 }
 
-cloneCase ()
+cloneCase()
 {
-    if [ -d $2 ] ; then
+    if [ -d $2 ]
+    then
         echo "Case already cloned: remove case directory $2 to clone"
     else
         echo "Cloning $2 case from $1"
diff --git a/bin/tools/inlineReplace b/bin/tools/inlineReplace
index 310787935a7aa856eb71508b4e74a2f2581a4a0a..4e502bccb2935dcd2d524b5fce1675f9a0ed1323 100755
--- a/bin/tools/inlineReplace
+++ b/bin/tools/inlineReplace
@@ -2,8 +2,9 @@
 
 # $0 string1 string2 file1 .. filen
 #
-if [ $# -lt 3 ]; then
-    echo "Usage: `basename $0` [-f] <string1> <string2> <file1> .. <filen>"
+if [ $# -lt 3 ]
+then
+    echo "Usage: ${0##*/} [-f] <string1> <string2> <file1> .. <filen>"
     echo ""
     echo "Replaces all occurrences of string1 by string2 in files."
     echo "(replacement of sed -i on those systems that don't support it)"
@@ -26,3 +27,5 @@ do
     #    echo "String $FROMSTRING not present in $f"
     #fi
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/bin/tools/replaceAllShellSun b/bin/tools/replaceAllShellSun
index 6c9fc5b70a1744dc442bffe9103b673a02231302..d5a0d8db9952fa878bd1289bdf89b4b981f6311b 100755
--- a/bin/tools/replaceAllShellSun
+++ b/bin/tools/replaceAllShellSun
@@ -1,8 +1,9 @@
 #!/usr/xpg4/bin/sh
 
 # Replace all shell script headers with 
-if [ $# -ne 1 -o ! -d "$1" ]; then
-    echo "Usage: `basename $0` <dir>"
+if [ $# -ne 1 -o ! -d "$1" ]
+then
+    echo "Usage: ${0##*/} <dir>"
     echo ""
     echo "Replaces all occurrences of #!/bin/sh with #!/usr/xpg4/bin/sh inside a directory tree."
     exit 1
@@ -13,3 +14,4 @@ fi
 
 find $1 -exec $WM_PROJECT_DIR/bin/tools/inlineReplace '^#\!/bin/sh' '#\!/usr/xpg4/bin/sh' {} \; -print
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/Allrun b/tutorials/Allrun
index b4e449dff6275aeb8c04fdbb342193009621b992..098f2f94f9f9ec34e76b514d44e2ec0b26068751 100755
--- a/tutorials/Allrun
+++ b/tutorials/Allrun
@@ -36,7 +36,8 @@ cd ${0%/*} || exit 1    # run from this directory
 
 # logReport <logfile>
 # Extracts useful info from log file.
-logReport () {
+logReport()
+{
     caseName=`dirname $1 | sed s/"\(.*\)\.\/"/""/g`
     app=`echo $1 | sed s/"\(.*\)\."/""/g`
     appAndCase="Application $app - case $caseName"
@@ -74,19 +75,18 @@ foamRunTutorials cases
 # Analyse all log files
 rm testLoopReport > /dev/null 2>&1 &
 touch testLoopReport
+
 for appDir in *
 do
-    if [ -d $appDir ]
-    then
-    (
-        cd $appDir
-        for log in `find . -name "log.*" | xargs ls -rt`
-        do
-            logReport $log >> ../testLoopReport
-        done
-        echo "" >> ../testLoopReport
-    )
-    fi
+(
+    [ -d $appDir ] && cd $appDir || exit
+
+    for log in `find . -name "log.*" | xargs ls -rt`
+    do
+        logReport $log >> ../testLoopReport
+    done
+    echo "" >> ../testLoopReport
+)
 done
 
 find . -name "log.*" -exec cat {} \; >> logs
diff --git a/tutorials/Alltest b/tutorials/Alltest
index b2965f0fee4f4b70f93c28e759482203efa47902..4769e04574ffa2895a5cf6f48262acd6f3fde736 100755
--- a/tutorials/Alltest
+++ b/tutorials/Alltest
@@ -32,7 +32,8 @@
 #------------------------------------------------------------------------------
 cd ${0%/*} || exit 1    # run from this directory
 
-usage() {
+usage()
+{
     while [ "$#" -ge 1 ]; do echo "$1"; shift; done
     cat<<USAGE
 
@@ -49,7 +50,8 @@ USAGE
 }
 
 
-setDefaultFvSchemes() {
+setDefaultFvSchemes()
+{
 cat<<EOF
 gradSchemes { default Gauss linear; }
 divSchemes
@@ -126,8 +128,12 @@ eval set -- "$OPTS"
 while [ $1 != -- ]
 do
     case $1 in
-        -d) DEFAULT_SCHEMES=1;;
-        -h) usage;;
+    -d)
+        DEFAULT_SCHEMES=1
+        ;;
+    -h)
+        usage
+        ;;
     esac
     shift
 done
diff --git a/tutorials/DNS/dnsFoam/boxTurb16/Allclean b/tutorials/DNS/dnsFoam/boxTurb16/Allclean
index 2bc9314020b437e793d91d279b945add11478619..9a9ff03ee175138c840b219b211e87a294c604d5 100755
--- a/tutorials/DNS/dnsFoam/boxTurb16/Allclean
+++ b/tutorials/DNS/dnsFoam/boxTurb16/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,3 +7,5 @@
 cleanCase
 rm -rf 0
 cp -r 0.org 0
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/DNS/dnsFoam/boxTurb16/Allrun b/tutorials/DNS/dnsFoam/boxTurb16/Allrun
index e005157d0978ecea54d006422f647e4522373801..f0ce8457aa7cb8e30c91298e83715080044ca8fa 100755
--- a/tutorials/DNS/dnsFoam/boxTurb16/Allrun
+++ b/tutorials/DNS/dnsFoam/boxTurb16/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -9,3 +11,5 @@ runApplication blockMesh
 runApplication boxTurb
 runApplication $application
 runApplication enstrophy
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/basic/laplacianFoam/flange/Allclean b/tutorials/basic/laplacianFoam/flange/Allclean
index 8e2a2600fe3e6b95e7cb2fa55c13b13798dce91e..a2e4493dcc5ad815825409bdadd25a0b4b71146a 100755
--- a/tutorials/basic/laplacianFoam/flange/Allclean
+++ b/tutorials/basic/laplacianFoam/flange/Allclean
@@ -1,8 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
-rm -rf Fieldview > /dev/null 2>&1
-rm -rf EnSight > /dev/null 2>&1
+rm -rf EnSight Ensight Fieldview > /dev/null 2>&1
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/basic/laplacianFoam/flange/Allrun b/tutorials/basic/laplacianFoam/flange/Allrun
index d6a968af469224bda3eb2dd2578f50577cfdb76f..db939bed7645b3812ce61fd4ebb7fee6583da63a 100755
--- a/tutorials/basic/laplacianFoam/flange/Allrun
+++ b/tutorials/basic/laplacianFoam/flange/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -20,3 +22,5 @@ runAnsysToFoam flange.ans 0.001
 runApplication $application
 runApplication foamToFieldview9
 runApplication foamToEnsight
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/basic/potentialFoam/Allclean b/tutorials/basic/potentialFoam/Allclean
index 5e0d99b090d4de92dca0d3e766b1ac38b1bd58d1..b81c740007908499f8ef2e3d698009099c41e46e 100755
--- a/tutorials/basic/potentialFoam/Allclean
+++ b/tutorials/basic/potentialFoam/Allclean
@@ -1,18 +1,25 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-cd cylinder
+(
+    cd cylinder || exit
+
     cleanCase
     rm -rf 0 > /dev/null 2>&1
     cp -r 0.org 0
     wclean analyticalCylinder
-cd ..
+)
+
+
+(
+    cd pitzDaily || exit
 
-cd pitzDaily
     cleanCase
     rm -rf 0 > /dev/null 2>&1
     cp -r 0.org 0
-cd ..
+)
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/basic/potentialFoam/cylinder/Allrun b/tutorials/basic/potentialFoam/cylinder/Allrun
index 36e2229aa640c4cb8e0eb6466cebf264ba1a5cb3..269683a112e4b515add1297eafcd86d782952ee4 100755
--- a/tutorials/basic/potentialFoam/cylinder/Allrun
+++ b/tutorials/basic/potentialFoam/cylinder/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -9,3 +11,5 @@ runApplication $application
 compileApplication analyticalCylinder
 runApplication analyticalCylinder
 runApplication streamFunction
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/basic/potentialFoam/pitzDaily/Allrun b/tutorials/basic/potentialFoam/pitzDaily/Allrun
index cadfe86d27327f23094cd02d4eb7224cdcbd8877..86fa0fdc4d690ec147a12c56059637bcf3d39e0d 100755
--- a/tutorials/basic/potentialFoam/pitzDaily/Allrun
+++ b/tutorials/basic/potentialFoam/pitzDaily/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ application=`getApplication`
 runApplication blockMesh
 runApplication $application
 runApplication streamFunction
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/combustion/XiFoam/ras/Allclean b/tutorials/combustion/XiFoam/ras/Allclean
index 04676f7732caea87cc5e694632f5900209431e09..9768a9af4697ea684e8ac7c83ff95160a70b5c8f 100755
--- a/tutorials/combustion/XiFoam/ras/Allclean
+++ b/tutorials/combustion/XiFoam/ras/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,12 +7,18 @@
 keepCases="moriyoshiHomogeneous"
 loseCases="moriyoshiHomogeneousPart2"
 
-for case in $keepCases
+for caseName in $keepCases
 do
-    (cd $case && foamCleanTutorials)
+(
+    cd $caseName || exit
+
+    foamCleanTutorials
+)
 done
 
-for case in $loseCases
+for caseName in $loseCases
 do
-    removeCase $case
+    removeCase $caseName
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/combustion/XiFoam/ras/Allrun b/tutorials/combustion/XiFoam/ras/Allrun
index 0c311946f1dfca601f372ab539d30cbf123f6316..6cb09e37d9e20855d7e0cbd8f40943bd6218b011 100755
--- a/tutorials/combustion/XiFoam/ras/Allrun
+++ b/tutorials/combustion/XiFoam/ras/Allrun
@@ -1,12 +1,16 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Set application name
 application="XiFoam"
 
-setControlDict () {
+setControlDict()
+{
     controlDict="system/controlDict"
+
     sed \
     -e s/"\(deltaT[ \t]*\) 5e-06;"/"\1 1e-05;"/g \
     -e s/"\(endTime[ \t]*\) 0.005;"/"\1 0.015;"/g \
@@ -15,15 +19,20 @@ setControlDict () {
     mv temp.$$ $controlDict
 }
 
+
 # Do moriyoshiHomogeneous
-(cd moriyoshiHomogeneous && foamRunTutorials)
+( cd moriyoshiHomogeneous && foamRunTutorials )
 
 # Clone case
 cloneCase moriyoshiHomogeneous moriyoshiHomogeneousPart2
 
 # Modify and execute
-cd moriyoshiHomogeneousPart2
+(
+    cd moriyoshiHomogeneousPart2 || exit
+
     cp -r ../moriyoshiHomogeneous/0.005 .
     setControlDict
     runApplication $application
-cd ..
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/combustion/engineFoam/kivaTest/Allclean b/tutorials/combustion/engineFoam/kivaTest/Allclean
index ac75ee552594e59180b2c34e09d30d352d8f56d3..77f5d3447858ab8ed7d884efe763741f62181fda 100755
--- a/tutorials/combustion/engineFoam/kivaTest/Allclean
+++ b/tutorials/combustion/engineFoam/kivaTest/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -8,3 +9,5 @@ rm -rf 0
 cp system/controlDict.1st system/controlDict
 cleanCase
 mv temp180 ./-180
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/combustion/engineFoam/kivaTest/Allrun b/tutorials/combustion/engineFoam/kivaTest/Allrun
index e8de444229f0ea65b9e4a2e033f78890b395602f..6c86823f996c3269898909f9293e0fe0e04246b8 100755
--- a/tutorials/combustion/engineFoam/kivaTest/Allrun
+++ b/tutorials/combustion/engineFoam/kivaTest/Allrun
@@ -1,32 +1,42 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Get application name
 application=`getApplication`
 
-runKivaToFoam ()
+runKivaToFoam()
 {
-    if [ -f $1/log.kivaToFoam ] ; then
-        echo "kivaToFoam already run on $1: remove log file to run"
+    if [ -f log.kivaToFoam ]
+    then
+        echo "kivaToFoam already run: remove log file to run"
     else
         echo "kivaToFoam: converting kiva file"
-        kivaToFoam -case $1 -file $2 > $1/log.kivaToFoam 2>&1
+        kivaToFoam -file $1 > log.kivaToFoam 2>&1
     fi
 }
 
-restartApplication ()
+
+restartApplication()
 {
-    if [ -f $2/log-2.$1 ] ; then
-        echo "$1 already run on $2: remove log file to run"
+    if [ -f log-2.$1 ]
+    then
+        echo "$1 already run: remove log file to run"
     else
-        echo "Running $1 on $2"
-        $1 -case $2 > $2/log-2.$1 2>&1
+        echo "Running $1"
+        $1 > log-2.$1 2>&1
     fi
 }
 
-runKivaToFoam . otape17
+
+runKivaToFoam otape17
+
 cp system/controlDict.1st system/controlDict
 runApplication $application
+
 cp system/controlDict.2nd system/controlDict
-restartApplication $application .
+restartApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/combustion/fireFoam/les/smallPoolFire2D/Allrun b/tutorials/combustion/fireFoam/les/smallPoolFire2D/Allrun
index 4d995124bb70bd6509a91a1cf07f4b2cb15c0bff..029f052ef4566a3d64006dbe7c16250068cbcf4d 100755
--- a/tutorials/combustion/fireFoam/les/smallPoolFire2D/Allrun
+++ b/tutorials/combustion/fireFoam/les/smallPoolFire2D/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -10,4 +12,4 @@ runApplication createPatch -overwrite
 # Run
 runApplication fireFoam
 
-# -----------------------------------------------------------------------------
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/rhoCentralFoam/Allclean b/tutorials/compressible/rhoCentralFoam/Allclean
index 4ac5daed0655f0707c67a13d96c66b30ab310250..b26e6cfb8ce97c6c56bf3bbcba56063c8528402d 100755
--- a/tutorials/compressible/rhoCentralFoam/Allclean
+++ b/tutorials/compressible/rhoCentralFoam/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -12,19 +13,25 @@ LadenburgJet60psi \
 biconic25-55Run35 \
 "
 
-for case in $cases
+for caseName in $cases
 do
-    if [ "$case" = "shockTube" ]
+(
+    cd $caseName || exit
+
+    if [ "$caseName" = shockTube ]
     then
-        rm -rf $case/0
-        cp -r $case/0.org $case/0
+        rm -rf 0
+        cp -r 0.org 0
     fi
 
-    (cd $case && foamCleanTutorials && cleanSamples)
+    foamCleanTutorials && cleanSamples
 
-    if [ "$case" = "biconic25-55Run35" ]
+    if [ "$caseName" = "biconic25-55Run35" ]
     then
-        rm -rf $case/constant/polyMesh/boundary
-        wclean $case/datToFoam
+        rm -rf constant/polyMesh/boundary
+        wclean datToFoam
     fi
+)
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/rhoCentralFoam/Allrun b/tutorials/compressible/rhoCentralFoam/Allrun
index d20d46fdd9b1cca90fae300cf18cf3192ce5ae79..fb311218eb10cb1222b99b1b7d95234fc60dbcc2 100755
--- a/tutorials/compressible/rhoCentralFoam/Allrun
+++ b/tutorials/compressible/rhoCentralFoam/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -14,26 +16,30 @@ LadenburgJet60psi \
 biconic25-55Run35 \
 "
 
-moveTimeMeshToConstant ()
+moveTimeMeshToConstant()
 {
    DT=`foamInfoExec -times | tail -1`
-   if [ "$DT" != 0 ] ; then
+   if [ "$DT" != 0 ]
+   then
        mv ${DT}/polyMesh/* constant/polyMesh
        rm -rf ${DT}
    fi
 }
 
-for case in $cases
+
+for caseName in $cases
 do
-    (cd $case && runApplication blockMesh)
-#
-    if [ "$case" = "shockTube" ] ; then
-        (cd $case && runApplication setFields)
-    fi
-#
-    if [ "$case" = "biconic25-55Run35" ] ; then
-        cd $case
+(
+    cd $caseName || exit
+
+    runApplication blockMesh
 
+    case "$caseName" in
+    shockTube)
+        runApplication setFields
+        ;;
+
+    biconic25-55Run35)
         wmake datToFoam
         runApplication datToFoam grid256.dat
 
@@ -46,9 +52,11 @@ do
         mv $CONST/polyMesh/boundary $CONST/polyMesh/boundary.bak
         sed -f $CONST/wedgeScr $CONST/polyMesh/boundary.bak > $CONST/polyMesh/boundary
         rm $CONST/polyMesh/boundary.bak
+        ;;
+    esac
 
-        cd ..
-    fi
-#
-    (cd $case && runApplication $application)
+    runApplication $application
+)
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/sampleCone b/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/sampleCone
index 29a4f5a3e29a298bb0c0bcadf9c0f7a540d460aa..25ee12e0ac60ae3af1ff3af08cfa043a494ada05 100755
--- a/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/sampleCone
+++ b/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/sampleCone
@@ -1,43 +1,54 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 #
 # FUNCTIONS
 #
-printUsage () {
-cat <<EOF
-Usage: $0 [options]
-Runs a set of samples across the cone face and concatenates output files
+usage()
+{
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+
+    cat<<USAGE
+Usage: ${0##*/} [OPTION]
+
+options:
+  -l         -latestTime option for sample
+  -h         help
 
-Options are:
--l         -latestTime option for sample
--h         help
-EOF
+Runs a set of samples across the cone face and concatenates output files
+USAGE
+    exit 1
 }
 
-LATEST_TIME=""
+
+unset timeOpt
 
 OPTS=`getopt hl $*`
-if [ $? -ne 0 ] ; then
-    echo "Aborting due to invalid option"
-    printUsage
-    exit 1
-fi
+[ $? -eq 0 ] || usage "Aborting due to invalid option"
+
 eval set -- "$OPTS"
-while [ $1 != -- ]; do
+while [ $1 != -- ]
+do
     case $1 in
-        -l) LATEST_TIME="-latestTime";;
-        -h) printUsage; exit 1;;
+    -l)
+        timeOpt="-latestTime"
+        ;;
+    -h)
+        usage
+        ;;
     esac
     shift
 done
 shift
 
-sample ${LATEST_TIME}
+sample $timeOpt
 SDIR="sets"
 LSDIR=`ls $SDIR | head -1`
 EXAMPLE_FILE=`ls -1 $SDIR/${LSDIR}/* | head -1`
 FS=`basename $EXAMPLE_FILE | cut -d_ -f2-`
 for d in $SDIR/*
 do
-   cat ${d}/cone25_${FS} ${d}/cone55_${FS} ${d}/base_${FS} > ${d}/biconic_${FS}
+    cat ${d}/cone25_${FS} ${d}/cone55_${FS} ${d}/base_${FS} > ${d}/biconic_${FS}
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/rhoSonicFoam/shockTube/Allrun b/tutorials/compressible/rhoSonicFoam/shockTube/Allrun
index 4f0a80edd84fab2c5980f3cd4000ff185d31acb0..de4d74c9da1caa4ea56e79b9cc4ba98b893977ed 100755
--- a/tutorials/compressible/rhoSonicFoam/shockTube/Allrun
+++ b/tutorials/compressible/rhoSonicFoam/shockTube/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -9,3 +11,5 @@ application=`getApplication`
 runApplication blockMesh
 runApplication setFields
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/rhopSonicFoam/shockTube/Allclean b/tutorials/compressible/rhopSonicFoam/shockTube/Allclean
index 8d3637cf52e9d1a15b81ecd52e550482f9b44b0b..5c160040dc279118c6ac7417dda3f8b415950fca 100755
--- a/tutorials/compressible/rhopSonicFoam/shockTube/Allclean
+++ b/tutorials/compressible/rhopSonicFoam/shockTube/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,3 +7,5 @@
 rm -rf 0
 cp -r 0.org 0
 cleanCase
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/rhopSonicFoam/shockTube/Allrun b/tutorials/compressible/rhopSonicFoam/shockTube/Allrun
index eede9049d770e4829fb2d746ebb736aab8cb5fb1..7b90a31601b62d6edf96a1054830e415e5170500 100755
--- a/tutorials/compressible/rhopSonicFoam/shockTube/Allrun
+++ b/tutorials/compressible/rhopSonicFoam/shockTube/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ application=`getApplication`
 runApplication blockMesh
 runApplication setFields
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean b/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean
index c8dbbe4c95f05ded3bcba9a45d4b5c2396c1f60d..ea6950dbccba1a28de5c93b9f883dba6d1db0858 100755
--- a/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean
+++ b/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -7,3 +8,5 @@ cleanCase
 rm -rf 0
 cp -r 0.org 0
 cleanSamples
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/sonicFoam/laminar/shockTube/Allrun b/tutorials/compressible/sonicFoam/laminar/shockTube/Allrun
index bb2d19c9ea6baadf8970df85062797ed5ae43121..05825201e75e2c31af454b417a71d3416f57dc1e 100755
--- a/tutorials/compressible/sonicFoam/laminar/shockTube/Allrun
+++ b/tutorials/compressible/sonicFoam/laminar/shockTube/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -9,3 +11,5 @@ runApplication setFields
 runApplication $application
 runApplication foamCalc mag U
 runApplication sample
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/sonicFoam/ras/nacaAirfoil/Allrun b/tutorials/compressible/sonicFoam/ras/nacaAirfoil/Allrun
index c2ae406306c56931aba8c609367cf52dc07d85ef..03afe0bd219d83c3efc636280b831332ac8ad9b6 100755
--- a/tutorials/compressible/sonicFoam/ras/nacaAirfoil/Allrun
+++ b/tutorials/compressible/sonicFoam/ras/nacaAirfoil/Allrun
@@ -1,11 +1,13 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Get application name
 application=`getApplication`
 
-runStarToFoam ()
+runStarToFoam()
 {
     if [ -f log.star3ToFoam -o -f log.starToFoam ]
     then
@@ -24,3 +26,5 @@ rm temp
 runApplication $application
 
 # end-of-file
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/sonicLiquidFoam/Allclean b/tutorials/compressible/sonicLiquidFoam/Allclean
index 50a10d24ffada6d62e8d1c12f8884f595eca63d2..fe284d4fded5e234ef53563d9ac9cf7b598e1346 100755
--- a/tutorials/compressible/sonicLiquidFoam/Allclean
+++ b/tutorials/compressible/sonicLiquidFoam/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 removeCase decompressionTankFine
 foamCleanTutorials cases
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/compressible/sonicLiquidFoam/Allrun b/tutorials/compressible/sonicLiquidFoam/Allrun
index 6d1d356b34507add807d1803fa0fd05ffda30394..16f2029d1893dcab33446b7241f6772123e9c3c2 100755
--- a/tutorials/compressible/sonicLiquidFoam/Allrun
+++ b/tutorials/compressible/sonicLiquidFoam/Allrun
@@ -1,14 +1,17 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Set application name
 application="sonicLiquidFoam"
 
-setDecompressionTankFine ()
+setDecompressionTankFine()
 {
-    blockMeshDict="$1/constant/polyMesh/blockMeshDict"
-    controlDict="$1/system/controlDict"
+    blockMeshDict="constant/polyMesh/blockMeshDict"
+    controlDict="system/controlDict"
+
     sed \
     -e s/"30 20"/"120 80"/g \
     -e s/"30 5"/"120 20"/g \
@@ -16,6 +19,7 @@ setDecompressionTankFine ()
     -e s/"30 95"/"120 380"/g \
     $blockMeshDict > temp.$$
     mv temp.$$ $blockMeshDict
+
     sed \
     -e s/"\(deltaT[ \t]*\) 5e-07;"/"\1 1e-07;"/g \
     -e s/"\(endTime[ \t]*\) 0.00025;"/"\1 0.00015;"/g \
@@ -23,16 +27,22 @@ setDecompressionTankFine ()
     mv temp.$$ $controlDict
 }
 
+
 # Do decompressionTank
-(cd decompressionTank && foamRunTutorials)
+( cd decompressionTank && foamRunTutorials )
 
 # Clone case
 cloneCase decompressionTank decompressionTankFine
 
-cd decompressionTankFine
+(
+    cd decompressionTankFine || exit
+
     # Modify case
-    setDecompressionTankFine .
+    setDecompressionTankFine
+
     # And execute
     runApplication blockMesh
     runApplication $application
-cd ..
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allclean b/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allclean
index 1cc972be26a9fa8c309f14c3c0d52659e62d236c..2bdc23621171942e2b9052b094b16398799fd265 100755
--- a/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allclean
+++ b/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 rm -rf 0/lagrangian 0/dsmcSigmaTcRMax
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allrun b/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allrun
index 3c61ac798ec54d2bf1f7f6c8799de3e396ab53c9..09d9f0ea78961fe2a5f73cc698509f0874c287ac 100755
--- a/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allrun
+++ b/tutorials/discreteMethods/dsmcFoam/freeSpacePeriodic/Allrun
@@ -1,7 +1,11 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 runApplication blockMesh
 runApplication dsmcInitialise
 runApplication dsmcFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allclean b/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allclean
index 1cc972be26a9fa8c309f14c3c0d52659e62d236c..2bdc23621171942e2b9052b094b16398799fd265 100755
--- a/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allclean
+++ b/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 rm -rf 0/lagrangian 0/dsmcSigmaTcRMax
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allrun b/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allrun
index 3c61ac798ec54d2bf1f7f6c8799de3e396ab53c9..09d9f0ea78961fe2a5f73cc698509f0874c287ac 100755
--- a/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allrun
+++ b/tutorials/discreteMethods/dsmcFoam/freeSpaceStream/Allrun
@@ -1,7 +1,11 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 runApplication blockMesh
 runApplication dsmcInitialise
 runApplication dsmcFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allclean b/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allclean
index 1cc972be26a9fa8c309f14c3c0d52659e62d236c..2bdc23621171942e2b9052b094b16398799fd265 100755
--- a/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allclean
+++ b/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 rm -rf 0/lagrangian 0/dsmcSigmaTcRMax
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allrun b/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allrun
index b36908112841487e6dd4b3e2f62b06cfb8d0167f..71795a47e0a13d48568403386be4af7886f09f7d 100755
--- a/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allrun
+++ b/tutorials/discreteMethods/dsmcFoam/supersonicCorner/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ runParallel dsmcInitialise 4
 runParallel dsmcFoam 4
 runApplication reconstructPar -noLagrangian
 
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allclean b/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allclean
index 1cc972be26a9fa8c309f14c3c0d52659e62d236c..2bdc23621171942e2b9052b094b16398799fd265 100755
--- a/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allclean
+++ b/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 rm -rf 0/lagrangian 0/dsmcSigmaTcRMax
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allrun b/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allrun
index b36908112841487e6dd4b3e2f62b06cfb8d0167f..71795a47e0a13d48568403386be4af7886f09f7d 100755
--- a/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allrun
+++ b/tutorials/discreteMethods/dsmcFoam/wedge15Ma5/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ runParallel dsmcInitialise 4
 runParallel dsmcFoam 4
 runApplication reconstructPar -noLagrangian
 
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allclean b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allclean
index d8245cb12bceacb3316f8f922262a9e911b9b155..5af6a2bb224d92840104f60f2c3ac94572068f60 100755
--- a/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allclean
+++ b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allclean
@@ -1,22 +1,30 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-cd periodicCubeArgon
+(
+    cd periodicCubeArgon || exit
+
     rm -rf 0/*
     rm -f Ar-Ar
     rm -f electrostatic
     rm -f constant/idList
     rm -rf constant/polyMesh/sets
     cleanCase
-cd ..
+)
+
+
+(
+    cd periodicCubeWater || exit
 
-cd periodicCubeWater
     rm -rf 0/*
     rm -f O-O
     rm -f electrostatic
     rm -f constant/idList
     rm -rf constant/polyMesh/sets
     cleanCase
-cd ..
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allrun b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allrun
index 59649516d94c727094c0725e9dd028a7c0a864d1..e849cf219a6ae6e4f5637eb4748e6044da3c3a00 100755
--- a/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allrun
+++ b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allrun
@@ -1,18 +1,20 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 application="mdEquilibrationFoam"
 
-cd periodicCubeArgon
-    runApplication blockMesh
-    runApplication mdInitialise
-    runApplication $application
-cd ..
+for caseName in periodicCubeArgon periodicCubeWater
+do
+(
+    cd $caseName || exit
 
-cd periodicCubeWater
     runApplication blockMesh
     runApplication mdInitialise
     runApplication $application
-cd ..
\ No newline at end of file
+)
+done
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allclean b/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allclean
index 8b3a55f4087fa2579b1626237c574e7bf492877f..36b77d9ac22c92003d0fc7073f569ec62f37de3b 100755
--- a/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allclean
+++ b/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,3 +7,5 @@
 rm -rf constant/polyMesh/sets
 rm -rf processor[0-9]
 cleanCase
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allrun b/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allrun
index 0e158046d9b3c2bd66712da3e68f9eb29df1282a..d60f30b22ae51270d051f116af8facdc075b0d2c 100755
--- a/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allrun
+++ b/tutorials/discreteMethods/molecularDynamics/mdFoam/nanoNozzle/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -13,3 +15,5 @@ runParallel mdInitialise 4
 runParallel $application 4
 
 runApplication reconstructPar
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/electromagnetics/mhdFoam/Allclean b/tutorials/electromagnetics/mhdFoam/Allclean
index b30c90e13b5398304475b406c33baa3c9536cdd8..f7eb365e0c757d5b80c6aaa5fee69e5aaf596dfc 100755
--- a/tutorials/electromagnetics/mhdFoam/Allclean
+++ b/tutorials/electromagnetics/mhdFoam/Allclean
@@ -1,7 +1,14 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-(cd hartmann && cleanCase)
-(cd hartmann && cleanSamples)
+(
+    cd hartmann || exit
+
+    cleanCase
+    cleanSamples
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/electromagnetics/mhdFoam/Allrun b/tutorials/electromagnetics/mhdFoam/Allrun
index f664a096985eb90c21bed0bb69b4b6327b0a226b..1b1a18565ff70ca324f181a8cc41651722961323 100755
--- a/tutorials/electromagnetics/mhdFoam/Allrun
+++ b/tutorials/electromagnetics/mhdFoam/Allrun
@@ -1,11 +1,19 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Set application name
 application="mhdFoam"
 
-(cd hartmann && runApplication blockMesh)
-(cd hartmann && runApplication $application)
-(cd hartmann && runApplication foamCalc components U)
-(cd hartmann && runApplication sample)
+(
+    cd hartmann || exit
+
+    runApplication blockMesh
+    runApplication $application
+    runApplication foamCalc components U
+    runApplication sample
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allclean b/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allclean
index 83fcec83ecad6243fdfd74b8afb16acd55518f36..25243dd42f8aff1c422994b6303af87d894424c3 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allclean
+++ b/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 cp 0/T.org 0/T
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allrun b/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allrun
index c3373651df31b91b556f2173779e63f6448eac26..814ade458e36f85190977d27fd5c9e27a843eb36 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allrun
+++ b/tutorials/heatTransfer/buoyantBoussinesqPisoFoam/hotRoom/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ compileApplication ../../buoyantPisoFoam/hotRoom/setHotRoom
 runApplication blockMesh
 runApplication setHotRoom
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allclean b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allclean
index 83fcec83ecad6243fdfd74b8afb16acd55518f36..25243dd42f8aff1c422994b6303af87d894424c3 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allclean
+++ b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 cp 0/T.org 0/T
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun
index c3373651df31b91b556f2173779e63f6448eac26..814ade458e36f85190977d27fd5c9e27a843eb36 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun
+++ b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ compileApplication ../../buoyantPisoFoam/hotRoom/setHotRoom
 runApplication blockMesh
 runApplication setHotRoom
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/iglooWithFridges/Allrun b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/iglooWithFridges/Allrun
index 79d959124fc56658dbdff086e4ccb22bdc0304e8..6fa85b7103f1979e249b33e8ea13b12b4397aacc 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/iglooWithFridges/Allrun
+++ b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/iglooWithFridges/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -6,3 +8,4 @@ runApplication blockMesh
 runApplication snappyHexMesh -overwrite
 runApplication buoyantBoussinesqSimpleFoam
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allclean b/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allclean
index 4310b6e01a42490974387cbff158168e69f64054..536b51a14e54034a9254d7a79312b3f89f9803e9 100755
--- a/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allclean
+++ b/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,3 +7,5 @@
 cleanCase
 cp 0/T.org 0/T
 wclean setHotRoom
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allrun b/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allrun
index e9bbb2d0c0082a1a5588d09aa0410915c31c62de..3aafa6fd9423021ecd3c0e5de1cc49cdfd7b0ede 100755
--- a/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allrun
+++ b/tutorials/heatTransfer/buoyantPisoFoam/hotRoom/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -9,3 +11,5 @@ compileApplication setHotRoom
 runApplication blockMesh
 runApplication setHotRoom
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allclean b/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allclean
index c5ab4caba94811d29469e8e18c311acbcdd7d69c..7f995e0041e023fafb12feb4fe30559e4486e635 100755
--- a/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allclean
+++ b/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allclean
@@ -1,7 +1,11 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 rm -rf sets
-(cd validation && rm -f *.eps)
+rm -f validation/*.eps
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allrun b/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allrun
index 5a8beb93c57efb85cfe982b15205321c64249a67..66c6a958972ed8e08dfb562541b22120eb917abd 100755
--- a/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allrun
+++ b/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,4 +10,7 @@ application="buoyantSimpleFoam"
 runApplication blockMesh
 runApplication $application
 runApplication sample -latestTime
-(cd validation && ./createGraphs)
+
+( cd validation && ./createGraphs )
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/validation/createGraphs b/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/validation/createGraphs
index 74eadd7127105f690ce6101f03c3a8b4c6125d85..0dec7ee1b62c6a9908fdf6e2e78aac7af5b4ee7f 100755
--- a/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/validation/createGraphs
+++ b/tutorials/heatTransfer/buoyantSimpleFoam/buoyantCavity/validation/createGraphs
@@ -32,7 +32,8 @@
 #
 #------------------------------------------------------------------------------
 
-createEpsT() {
+createEpsT()
+{
     index=$1
     OF=$2
     EXPT=$3
@@ -54,7 +55,8 @@ EOF
 }
 
 
-createEpsU() {
+createEpsU()
+{
     index=$1
     OF=$2
     EXPT=$3
@@ -78,7 +80,8 @@ EOF
 
 # test if gnuplot exists on the system
 type -P gnuplot &>/dev/null || {
-    echo "gnuplot not found - skipping graph creation" >&2; exit 1;
+    echo "gnuplot not found - skipping graph creation" >&2
+    exit 1
 }
 
 # paths to data
@@ -89,7 +92,8 @@ EXPTDATAROOT=./exptData
 
 # generate temperature profiles
 TSets="1 3 4 5 6 7 9"
-for i in $TSets; do
+for i in $TSets
+do
     echo "    processing temperature profile at y/yMax of 0.$i"
 
     OF="$OFDATAROOT/y0.${i}_T.xy"
@@ -101,7 +105,8 @@ done
 
 # generate velocity profiles
 USets="1 3 4 5 6 7 9"
-for i in $USets; do
+for i in $USets
+do
     echo "    processing velocity profile at y/yMax of 0.$i"
 
     OF="$OFDATAROOT/y0.${i}_U.xy"
@@ -110,6 +115,6 @@ for i in $USets; do
     createEpsU $i $OF $EXPT
 done
 
-echo "done"
+echo Done
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allclean b/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allclean
index 83fcec83ecad6243fdfd74b8afb16acd55518f36..25243dd42f8aff1c422994b6303af87d894424c3 100755
--- a/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allclean
+++ b/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 cp 0/T.org 0/T
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allrun b/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allrun
index c3373651df31b91b556f2173779e63f6448eac26..814ade458e36f85190977d27fd5c9e27a843eb36 100755
--- a/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allrun
+++ b/tutorials/heatTransfer/buoyantSimpleFoam/hotRoom/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ compileApplication ../../buoyantPisoFoam/hotRoom/setHotRoom
 runApplication blockMesh
 runApplication setHotRoom
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allclean b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allclean
index a76e8dff53cb6dd7c244c39473ce569b56389e1d..01acce567027f86bc81805aefd0daaa43cd52369 100755
--- a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allclean
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -18,4 +19,4 @@ rm -rf constant/heater/polyMesh
 rm -rf constant/leftSolid/polyMesh
 rm -rf constant/rightSolid/polyMesh
 
-# -----------------------------------------------------------------------------
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allrun b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allrun
index 231c46e6ec332c7aaed3b9e8d7c63cf01f835571..8a25708db643118931960623480808d1988d5974 100755
--- a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allrun
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -58,4 +60,4 @@ do
    paraFoam -touch -region $i
 done
 
-# -----------------------------------------------------------------------------
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allclean b/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allclean
index a76e8dff53cb6dd7c244c39473ce569b56389e1d..01acce567027f86bc81805aefd0daaa43cd52369 100755
--- a/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allclean
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -18,4 +19,4 @@ rm -rf constant/heater/polyMesh
 rm -rf constant/leftSolid/polyMesh
 rm -rf constant/rightSolid/polyMesh
 
-# -----------------------------------------------------------------------------
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allrun b/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allrun
index 5b96ab937d0d0d3fb41119ba514d65ad38a2bc35..d5e265222269f536aa06f4d0a7b83d82a9920163 100755
--- a/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allrun
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -55,4 +57,4 @@ do
    paraFoam -touch -region $i
 done
 
-# -----------------------------------------------------------------------------
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/MRFSimpleFoam/mixerVessel2D/Allrun b/tutorials/incompressible/MRFSimpleFoam/mixerVessel2D/Allrun
index 836276fe9cea7a027c4726fa021088bf33d0da6e..9210b03c391f4c2ba98621f6e326e152eda02c28 100755
--- a/tutorials/incompressible/MRFSimpleFoam/mixerVessel2D/Allrun
+++ b/tutorials/incompressible/MRFSimpleFoam/mixerVessel2D/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -7,3 +9,5 @@ application=`getApplication`
 
 ./makeMesh
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allclean b/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allclean
index f236efc56e2a5d2a74fc710122529fa070e27d4c..53e777c12cbc7327c4e212c9b173de116de0e34b 100755
--- a/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allclean
+++ b/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -7,3 +8,5 @@ cleanCase
 
 rm -rf logs
 rm -f *.eps yPlus_vs_uPlus
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allrun b/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allrun
index 6f45774974f33a24cafbddc7325cd1252514c8b1..9a27a17f14d7d49a3ac2108c16fedcd233c1bfd2 100755
--- a/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allrun
+++ b/tutorials/incompressible/boundaryFoam/boundaryWallFunctionsProfile/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -9,7 +10,8 @@ exponents="2 3 4 5 6 7 8"
 
 echo "# yPlus vs uPlus" > yPlus_vs_uPlus
 
-for e in $exponents; do
+for e in $exponents
+do
     echo "    Setting nu to 1e-$e"
 
     sed "s/XXX/$e/g" constant/transportProperties.template \
@@ -25,7 +27,8 @@ for e in $exponents; do
 
     mv log.foamLog log.foamLog_$e
 
-    if [ -e logs/yPlus_0 ]; then
+    if [ -e logs/yPlus_0 ]
+    then
         yPlus=`awk < logs/yPlus_0 'END{print $2}'`
         uPlus=`awk < logs/uPlus_0 'END{print $2}'`
 
@@ -39,7 +42,8 @@ done
 # create validation plot
 # test if gnuplot exists on the system
 type -P gnuplot &>/dev/null || {
-    echo "gnuplot not found - skipping graph creation" >&2; exit 1;
+    echo "gnuplot not found - skipping graph creation" >&2
+    exit 1
 }
 graphName="OF_vs_ANAYTICAL.eps"
 
@@ -65,5 +69,6 @@ gnuplot<<EOF
         "yPlus_vs_uPlus" title "OpenFOAM" with points lt 1 pt 6
 EOF
 
+echo Done
 
-echo "done"
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/channelFoam/channel395/Allrun b/tutorials/incompressible/channelFoam/channel395/Allrun
index 05cd6dfdf017c560e257fd4136e11938bbeadf02..61c1b54530e027a68bf1199743afea0f485ce81f 100755
--- a/tutorials/incompressible/channelFoam/channel395/Allrun
+++ b/tutorials/incompressible/channelFoam/channel395/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ application=`getApplication`
 runApplication blockMesh
 runApplication $application
 runApplication postChannel
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/icoFoam/Allclean b/tutorials/incompressible/icoFoam/Allclean
index 4ead7ee3ea846cfb698273167773dbb5859247d1..c09ae6c8d9e605a578421e2955a12a75d8930fe3 100755
--- a/tutorials/incompressible/icoFoam/Allclean
+++ b/tutorials/incompressible/icoFoam/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,17 +7,23 @@
 keepCases="cavity cavityGrade cavityClipped elbow"
 loseCases="cavityFine cavityHighRe"
 
-for case in $keepCases
+for caseName in $keepCases
 do
-    (cd $case && foamCleanTutorials)
+(
+    cd $caseName || exit
 
-    if [ "$case" = "elbow" ]
+    foamCleanTutorials
+
+    if [ "$caseName" = elbow ]
     then
-        rm -rf $case/fluentInterface
+        rm -rf fluentInterface
     fi
+)
 done
 
-for case in $loseCases
+for caseName in $loseCases
 do
-    removeCase $case
+    removeCase $caseName
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/icoFoam/Allrun b/tutorials/incompressible/icoFoam/Allrun
index 1a93d4eb327caa21863b16ab13ba1e5e7e0d1af2..185f95b9793d7fae190e0a6e3d2ba4f38fdf582e 100755
--- a/tutorials/incompressible/icoFoam/Allrun
+++ b/tutorials/incompressible/icoFoam/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,34 +9,34 @@ application="icoFoam"
 
 cavityCases="cavity cavityFine cavityGrade cavityHighRe cavityClipped"
 
-runMapFields ()
+runMapFields()
 {
     echo "Running mapFields from $1 to $2"
     mapFields $1 -case $2 -sourceTime latestTime > $2/log.mapFields 2>&1
 }
 
-runMapFieldsConsistent ()
+runMapFieldsConsistent()
 {
     echo "Running mapFields from $1 to $2"
     mapFields $1 -case $2 -sourceTime latestTime -consistent > $2/log.mapFields 2>&1
 }
 
-runFluentMeshToFoam ()
+runFluentMeshToFoam()
 {
     echo "fluentMeshToFoam: converting mesh $2"
     fluentMeshToFoam $2 -case $1 > $1/log.fluentMeshToFoam 2>&1
 }
 
-copySolutionDirs ()
+copySolutionDirs()
 {
     echo "Copying $2/0* directory to $1"
     cp -r $2/0* $1
 }
 
-setCavityFine ()
+setCavityFine()
 {
-    blockMeshDict="$case/constant/polyMesh/blockMeshDict"
-    controlDict="$case/system/controlDict"
+    blockMeshDict="$caseName/constant/polyMesh/blockMeshDict"
+    controlDict="$caseName/system/controlDict"
     sed s/"20 20 1"/"41 41 1"/g $blockMeshDict > temp.$$
     mv temp.$$ $blockMeshDict
     sed \
@@ -47,11 +49,11 @@ setCavityFine ()
     mv temp.$$ $controlDict
 }
 
-setCavityHighRe ()
+setCavityHighRe()
 {
     echo "Setting cavityHighRe to generate a secondary vortex"
-    controlDict="$case/system/controlDict"
-    transportProperties="$case/constant/transportProperties"
+    controlDict="$caseName/system/controlDict"
+    transportProperties="$caseName/constant/transportProperties"
     sed \
     -e s/"\(startFrom[ \t]*\) startTime;"/"\1 latestTime;"/g \
     -e s/"\(endTime[ \t]*\) 0.5;"/"\1 2.0;"/g \
@@ -61,47 +63,53 @@ setCavityHighRe ()
     mv temp.$$ $transportProperties
 }
 
-for case in $cavityCases
+
+for caseName in $cavityCases
 do
-    if [ "$case" = "cavityFine" ]
+    if [ "$caseName" = cavityFine ]
     then
-        cloneCase cavity $case
+        cloneCase cavity $caseName
         setCavityFine
     fi
 
-    if [ "$case" = "cavityHighRe" ]
+    if [ "$caseName" = cavityHighRe ]
     then
-        cloneCase cavity $case
+        cloneCase cavity $caseName
         setCavityHighRe
-        copySolutionDirs $case cavity
+        copySolutionDirs $caseName cavity
     fi
 
-    (cd $case && runApplication blockMesh)
-#
-    if [ "$case" = "cavityFine" -o "$case" = "cavityGrade" ]
-    then
-        runMapFieldsConsistent $previousCase $case
-    fi
+    ( cd $caseName && runApplication blockMesh )
 
-    if [ "$case" = "cavityClipped" ]
-    then
-        cp -r $case/0 $case/0.5
-        runMapFields cavity $case
-        if [ ".`grep nonuniform $case/0.5/U`" != "." ]
+    case "$caseName" in
+    cavityFine | cavityGrade)
+        runMapFieldsConsistent $previousCase $caseName
+        ;;
+    cavityClipped)
+        cp -r $caseName/0 $caseName/0.5
+        runMapFields cavity $caseName
+        if [ ".`grep nonuniform $caseName/0.5/U`" != "." ]
         then
-            sed -f resetFixedWallsScr $case/0.5/U > $case/0.5/U.temp
-            mv $case/0.5/U.temp $case/0.5/U
+            sed -f resetFixedWallsScr $caseName/0.5/U > $caseName/0.5/U.temp
+            mv $caseName/0.5/U.temp $caseName/0.5/U
         fi
-    fi
-#
-    previousCase="$case"
-#
-    (cd $case && runApplication $application)
+        ;;
+    esac
+
+    previousCase="$caseName"
+    ( cd $caseName && runApplication $application )
 done
 
 # elbow case for testing Fluent-FOAM conversion tools
 
 runFluentMeshToFoam elbow elbow/elbow.msh
-(cd elbow && runApplication $application)
-(cd elbow && runApplication foamMeshToFluent)
-(cd elbow && runApplication foamDataToFluent)
+
+(
+    cd elbow || exit
+
+    runApplication $application
+    runApplication foamMeshToFluent
+    runApplication foamDataToFluent
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/Allrun b/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/Allrun
index aeb984814c564005dcc12204ed6a005894f2f99f..5cf2386bfa6600a4a07c3ed771901886a0baa336 100755
--- a/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/Allrun
+++ b/tutorials/incompressible/pisoFoam/les/pitzDailyDirectMapped/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ application=`getApplication`
 runApplication blockMesh
 runApplication changeDictionary
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/simpleFoam/airFoil2D/Allclean b/tutorials/incompressible/simpleFoam/airFoil2D/Allclean
index 35e38c65c54b6620f679d4494c76cc03f97cdd57..e0102f95da61148486642f2d11c341c043e6a4fe 100755
--- a/tutorials/incompressible/simpleFoam/airFoil2D/Allclean
+++ b/tutorials/incompressible/simpleFoam/airFoil2D/Allclean
@@ -1,6 +1,9 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Clean time folders only
 
 rm -rf *[1-9]*
 rm -f log.* 2>/dev/null
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/simpleFoam/airFoil2D/Allrun b/tutorials/incompressible/simpleFoam/airFoil2D/Allrun
index 411704d7836a4f61312e668b2f93d4ae057a8e22..581f44483939f4932fc1109584308429c983a99d 100755
--- a/tutorials/incompressible/simpleFoam/airFoil2D/Allrun
+++ b/tutorials/incompressible/simpleFoam/airFoil2D/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -6,3 +7,5 @@
 application=`getApplication`
 
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/incompressible/simpleFoam/motorBike/Allrun b/tutorials/incompressible/simpleFoam/motorBike/Allrun
index 7e6037f4cda17672f6eb05aa84677958521f8d7c..802112d8b86983287e0868160767fd83f12274bc 100755
--- a/tutorials/incompressible/simpleFoam/motorBike/Allrun
+++ b/tutorials/incompressible/simpleFoam/motorBike/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -6,3 +8,4 @@ runApplication blockMesh
 runApplication snappyHexMesh -overwrite
 runApplication simpleFoam
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/Allrun b/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/Allrun
index 945c8974dfc7003e127eeb307d1fa26a1e1f379d..a67553deb14e863ee3f35a13ce357064e89f0591 100755
--- a/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/Allrun
+++ b/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -12,3 +13,5 @@ runApplication blockMesh
 runApplication cellSet
 
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allclean b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allclean
index 1dac791f4b9848b3cdfca87df338be508d1fc70e..3f107970554bb131912d53d98a9a8b3ae469a37c 100755
--- a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allclean
+++ b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -13,3 +14,5 @@ rm -rf postProcessing
 
 # copy 0.org to 0
 cp -r 0.org 0
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allrun b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allrun
index 04eb8794e0cd381b38c3c9f2e77fbe2595364760..b44a7c8e2f7be6290578156d30d38091665d74a7 100755
--- a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allrun
+++ b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/filter/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -22,3 +23,5 @@ createBaffles cycLeft cycLeft -overwrite >& log.createBaffles1
 createBaffles cycRight cycRight -overwrite >& log.createBaffles2
 
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allclean b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allclean
index fbf6469b87cff2c2e53cbbcb68525ad3ff1e240a..6ac02e9eab65bae4e3a6e69678372d9b9b15a274 100755
--- a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allclean
+++ b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allclean
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
@@ -11,3 +13,4 @@ cp -r 0.org 0
 
 cleanCase
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allrun b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allrun
index 6eb3715e653e3f89c25d0ecfbe2b8ff619795da1..40f241728a77b1894888e145bbe1f1ec5ee57c24 100755
--- a/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allrun
+++ b/tutorials/lagrangian/porousExplicitSourceReactingParcelFoam/verticalChannel/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -11,3 +13,5 @@ rm -f 0/phi
 
 # run the solver
 runApplication porousExplicitSourceReactingParcelFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/mesh/snappyHexMesh/Allrun b/tutorials/mesh/snappyHexMesh/Allrun
index 90979fcb05013ab6b317c207cd1dee788860bb93..d15026b3b0d6c81a2b063b40bf86528de5216406 100755
--- a/tutorials/mesh/snappyHexMesh/Allrun
+++ b/tutorials/mesh/snappyHexMesh/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 exit 0
 
@@ -7,3 +8,4 @@ exit 0
 
 # This dummy Allrun script avoids meshing these cases twice.
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/cavitatingFoam/les/Allclean b/tutorials/multiphase/cavitatingFoam/les/Allclean
index 35d86a21214f38680ba0c097517688eab7450a9f..fae8abfab6ac1ea15d5a90c621f49283fef00012 100755
--- a/tutorials/multiphase/cavitatingFoam/les/Allclean
+++ b/tutorials/multiphase/cavitatingFoam/les/Allclean
@@ -1,17 +1,23 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-cd throttle
+(
+    cd throttle || exit
+
     rm -rf constant/polyMesh/sets > /dev/null 2>&1
     rm -rf 0/polyMesh > /dev/null 2>&1
     rm system/cellSetDict > /dev/null 2>&1
 
     cleanCase
-cd ..
+)
+
+
+(
+    cd throttle3D || exit
 
-cd throttle3D
     rm -rf constant/polyMesh/sets > /dev/null 2>&1
     rm -rf 0 > /dev/null 2>&1
     cp -r 0.org 0
@@ -19,5 +25,6 @@ cd throttle3D
     rm -rf processor[0-9] > /dev/null 2>&1
 
     cleanCase
-cd ..
+)
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/cavitatingFoam/les/Allrun b/tutorials/multiphase/cavitatingFoam/les/Allrun
index c6b98bda754e16c0a63cee7214e4ce817626bab1..caff26f5710565c3a7b6f59ac4700c0fa745bdff 100755
--- a/tutorials/multiphase/cavitatingFoam/les/Allrun
+++ b/tutorials/multiphase/cavitatingFoam/les/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -20,13 +21,19 @@ refineMeshByCellSet()
    done
 }
 
-cd throttle
+
+(
+    cd throttle || exit
+
     runApplication blockMesh
     refineMeshByCellSet 1 2 3
     runApplication $application
-cd ..
+)
+
+
+(
+    cd throttle3D || exit
 
-cd throttle3D
     cp -r 0.org 0
 
     runApplication blockMesh
@@ -38,5 +45,6 @@ cd throttle3D
     runApplication decomposePar
     runParallel $application 4
     runApplication reconstructPar
-cd ..
+)
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/cavitatingFoam/ras/throttle/Allclean b/tutorials/multiphase/cavitatingFoam/ras/throttle/Allclean
index 224fbd6f0e714cd4e9f9a21ec1971bf3210fcdbf..96f4954120902b82775fb4306988b750b9ffc867 100755
--- a/tutorials/multiphase/cavitatingFoam/ras/throttle/Allclean
+++ b/tutorials/multiphase/cavitatingFoam/ras/throttle/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -7,3 +8,5 @@ rm -rf constant/polyMesh/sets > /dev/null 2>&1
 rm -rf 0/polyMesh > /dev/null 2>&1
 rm system/cellSetDict > /dev/null 2>&1
 cleanCase
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/cavitatingFoam/ras/throttle/Allrun b/tutorials/multiphase/cavitatingFoam/ras/throttle/Allrun
index 7f095c44f177400ba70afa234433b5a9aae1602f..878222cf8073e32639ef1ac88124d48eec31a2ac 100755
--- a/tutorials/multiphase/cavitatingFoam/ras/throttle/Allrun
+++ b/tutorials/multiphase/cavitatingFoam/ras/throttle/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -23,3 +24,4 @@ runApplication blockMesh
 refineMeshByCellSet 1 2 3
 runApplication $application
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/compressibleInterFoam/les/depthCharge2D/Allrun b/tutorials/multiphase/compressibleInterFoam/les/depthCharge2D/Allrun
index a3d54875d4a261e0a14965700a18eb81bb7a568e..2e0fd036f2c1e961c065cd0eff41f647fa29fb3b 100755
--- a/tutorials/multiphase/compressibleInterFoam/les/depthCharge2D/Allrun
+++ b/tutorials/multiphase/compressibleInterFoam/les/depthCharge2D/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -10,3 +12,5 @@ cp 0/alpha1.org 0/alpha1
 cp 0/p.org 0/p
 runApplication setFields
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allclean b/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allclean
index 99cd62d9236e42bc0e1303987403265889e6fb6b..6633e983d1d4584494504392fd1165090980f252 100755
--- a/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allclean
+++ b/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allclean
@@ -1,5 +1,8 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf processor*
 rm -rf 0/p.gz 0/alpha1.gz
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allrun b/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allrun
index 695ef4d671a213fe27b4b2235133c729c6ccc83a..c77d2e8fc2eac1ddf9da2ca970254121986f4a39 100755
--- a/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allrun
+++ b/tutorials/multiphase/compressibleInterFoam/les/depthCharge3D/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -12,3 +14,5 @@ runApplication setFields
 runApplication decomposePar
 runParallel $application 4
 runApplication reconstructPar
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun b/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun
index ce475808debf880fa195495d9b7d6f5fc1ff8c63..deafedf7a63b23016946bb3e00b199bfb2daf729 100755
--- a/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ runApplication setSet -batch createObstacle.setSet
 runApplication subsetMesh c0 -patch walls
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allclean b/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allclean
index 2cd0673fdd5e684d4862ad4f10019588b8c5d95a..2c6db87c7f2bb23426b422dc88288ae44ead4a52 100755
--- a/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -8,3 +9,4 @@ rm -rf 0 > /dev/null 2>&1
 
 cleanCase
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun b/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun
index 7c7ab52940262234486363281c2195f97e86b06e..8016666d736b3578214f1f73ea686ba14240b8ce 100755
--- a/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -24,4 +25,4 @@ cp -r 0.org 0 > /dev/null 2>&1
 runApplication setFields
 runApplication $application
 
-# -----------------------------------------------------------------------------
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allclean b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allclean
index 20c2a63671cad1633195e872d98b63d22c2cd156..a65375ff722ee52cde31730b6ed15ab56b8a8dfb 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha1.gz probes wallPressure pRefProbe
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allrun b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allrun
index 0d2a8c82229717af79be19a0037784058a171958..593a959d00a16288426cb42f2b369b2ee74aa411 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ runApplication blockMesh
 cp 0/alpha1.org 0/alpha1
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allclean b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allclean
index 20c2a63671cad1633195e872d98b63d22c2cd156..a65375ff722ee52cde31730b6ed15ab56b8a8dfb 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha1.gz probes wallPressure pRefProbe
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allrun b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allrun
index 0d2a8c82229717af79be19a0037784058a171958..593a959d00a16288426cb42f2b369b2ee74aa411 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank2D3DoF/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ runApplication blockMesh
 cp 0/alpha1.org 0/alpha1
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allclean b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allclean
index 20c2a63671cad1633195e872d98b63d22c2cd156..a65375ff722ee52cde31730b6ed15ab56b8a8dfb 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha1.gz probes wallPressure pRefProbe
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allrun b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allrun
index 0d2a8c82229717af79be19a0037784058a171958..593a959d00a16288426cb42f2b369b2ee74aa411 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ runApplication blockMesh
 cp 0/alpha1.org 0/alpha1
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allclean b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allclean
index 20c2a63671cad1633195e872d98b63d22c2cd156..a65375ff722ee52cde31730b6ed15ab56b8a8dfb 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha1.gz probes wallPressure pRefProbe
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allrun b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allrun
index 0d2a8c82229717af79be19a0037784058a171958..593a959d00a16288426cb42f2b369b2ee74aa411 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D3DoF/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ runApplication blockMesh
 cp 0/alpha1.org 0/alpha1
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allclean b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allclean
index 20c2a63671cad1633195e872d98b63d22c2cd156..a65375ff722ee52cde31730b6ed15ab56b8a8dfb 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha1.gz probes wallPressure pRefProbe
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allrun b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allrun
index 0d2a8c82229717af79be19a0037784058a171958..593a959d00a16288426cb42f2b369b2ee74aa411 100755
--- a/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/sloshingTank3D6DoF/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -7,3 +9,5 @@ runApplication blockMesh
 cp 0/alpha1.org 0/alpha1
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allclean b/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allclean
index 069278e17c3f8291ab35612a969daf394bd41af5..4b3e979c4a186c0aacc698997691a0ba604c672e 100755
--- a/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allclean
+++ b/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha1.gz
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allrun b/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allrun
index aaf67a1250f3004b76290d95eaf7f5a2bc272dc8..9b42e0115faeb692e74ca6d2ccaafde2035f0ece 100755
--- a/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/testTubeMixer/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -6,3 +8,5 @@ runApplication blockMesh
 cp 0/alpha1.org 0/alpha1
 runApplication setFields
 runApplication interDyMFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/MRFInterFoam/mixerVessel2D/Allrun b/tutorials/multiphase/interFoam/MRFInterFoam/mixerVessel2D/Allrun
index 99a20900eb96f8f71086983851443c0afa6b1155..a718eaf7e662bad616179bd183caa9fd72de8b79 100755
--- a/tutorials/multiphase/interFoam/MRFInterFoam/mixerVessel2D/Allrun
+++ b/tutorials/multiphase/interFoam/MRFInterFoam/mixerVessel2D/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -7,3 +8,5 @@ application=`getApplication`
 
 runApplication ./makeMesh
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/laminar/Allclean b/tutorials/multiphase/interFoam/laminar/Allclean
index 6ad97e1a0bd7ffd8f0073bb9a1f9f9d3391d7c6b..114bd5f0cb46b911b1776b65ddb22dc3d189508d 100755
--- a/tutorials/multiphase/interFoam/laminar/Allclean
+++ b/tutorials/multiphase/interFoam/laminar/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,17 +7,23 @@
 keepCases="damBreak"
 loseCases="damBreakFine"
 
-for case in $keepCases
+for caseName in $keepCases
 do
-    (cd $case && foamCleanTutorials)
+(
+    cd $caseName || exit
 
-    if [ "$case" = "damBreak" ]
+    foamCleanTutorials
+
+    if [ "$caseName" = damBreak ]
     then
-        cp $case/0/alpha1.org $case/0/alpha1
+        cp 0/alpha1.org 0/alpha1
     fi
+)
 done
 
-for case in $loseCases
+for caseName in $loseCases
 do
-    removeCase $case
+    removeCase $caseName
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/laminar/Allrun b/tutorials/multiphase/interFoam/laminar/Allrun
index 03ffbeecde3c00d170e416054f8dfb99a544b4cb..3b03260773615f1f1f96cb434c964f906b0b587c 100755
--- a/tutorials/multiphase/interFoam/laminar/Allrun
+++ b/tutorials/multiphase/interFoam/laminar/Allrun
@@ -1,14 +1,17 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Set application name
 application="interFoam"
 
-setDamBreakFine ()
+setDamBreakFine()
 {
     blockMeshDict="constant/polyMesh/blockMeshDict"
     controlDict="system/controlDict"
+
     sed \
     -e s/"23 8"/"46 10"/g \
     -e s/"19 8"/"40 10"/g \
@@ -17,6 +20,7 @@ setDamBreakFine ()
     -e s/"19 42\(.*\) 1 1)"/"40 76\1 2 1)"/g \
     $blockMeshDict > temp.$$
     mv temp.$$ $blockMeshDict
+
     sed \
     -e s/"\(deltaT[ \t]*\) 0.001;"/"\1 5e-04;"/g \
     -e s/"\(endTime[ \t]*\) 1;"/"\1 0.4;"/g \
@@ -25,23 +29,30 @@ setDamBreakFine ()
 }
 
 # Do damBreak
-cd damBreak
+(
+    cd damBreak || exit
+
     runApplication blockMesh
     runApplication setFields
     runApplication $application
-cd ..
+)
 
 # Clone case
 cloneCase damBreak damBreakFine
 
-cd damBreakFine
+(
+    cd damBreakFine || exit
+
     # Modify case
     setDamBreakFine
     cp ../damBreak/0/alpha1.org 0/alpha1
+
     # And execute
     runApplication blockMesh
     runApplication setFields
     runApplication decomposePar
     runParallel $application 4
     runApplication reconstructPar
-cd ..
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allclean b/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allclean
index 0bf8736235a0e57625564835099d2ca139b932ac..cb4e2bd79201e5994ab07f6378c74dbad278b54d 100755
--- a/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allclean
+++ b/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allclean
@@ -1,7 +1,10 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
 cp constant/polyMesh/boundary.org constant/polyMesh/boundary
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allrun b/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allrun
index 655eb4c8874e3c19195c318867379af30162833f..c233dfa35686061c78ae2ff691c49d1637967800 100755
--- a/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allrun
+++ b/tutorials/multiphase/interFoam/les/nozzleFlow2D/Allrun
@@ -1,24 +1,31 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Get application name
 application=`getApplication`
 
-runRefineMesh ()
+runRefineMesh()
 {
     echo "Running refineMesh on $PWD"
     refineMesh -dict > log.refineMesh 2>&1
 }
 
+
 runApplication blockMesh
 
 i=1
-if [ -f log.cellSet ] ; then
-   i=3
+if [ -f log.cellSet ]
+then
+    i=3
 fi
-while [ "$i" -lt 3 ] ; do
-    if [ -f log.cellSet ] ; then
+
+while [ "$i" -lt 3 ]
+do
+    if [ -f log.cellSet ]
+    then
         mv log.cellSet log.cellSet.1
     fi
     cp system/cellSetDict.${i} system/cellSetDict
@@ -31,3 +38,5 @@ done
 cp constant/polyMesh/boundary.org constant/polyMesh/boundary
 
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/ras/Allclean b/tutorials/multiphase/interFoam/ras/Allclean
index 6ad97e1a0bd7ffd8f0073bb9a1f9f9d3391d7c6b..114bd5f0cb46b911b1776b65ddb22dc3d189508d 100755
--- a/tutorials/multiphase/interFoam/ras/Allclean
+++ b/tutorials/multiphase/interFoam/ras/Allclean
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
@@ -6,17 +7,23 @@
 keepCases="damBreak"
 loseCases="damBreakFine"
 
-for case in $keepCases
+for caseName in $keepCases
 do
-    (cd $case && foamCleanTutorials)
+(
+    cd $caseName || exit
 
-    if [ "$case" = "damBreak" ]
+    foamCleanTutorials
+
+    if [ "$caseName" = damBreak ]
     then
-        cp $case/0/alpha1.org $case/0/alpha1
+        cp 0/alpha1.org 0/alpha1
     fi
+)
 done
 
-for case in $loseCases
+for caseName in $loseCases
 do
-    removeCase $case
+    removeCase $caseName
 done
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/ras/Allrun b/tutorials/multiphase/interFoam/ras/Allrun
index c01559fc7760107018a2ad7d0d65f79866915e35..059151a12c3ffd1c5a5be51c3a637d0179114379 100755
--- a/tutorials/multiphase/interFoam/ras/Allrun
+++ b/tutorials/multiphase/interFoam/ras/Allrun
@@ -1,14 +1,17 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Set application name
 application="interFoam"
 
-setDamBreakFine ()
+setDamBreakFine()
 {
     blockMeshDict="constant/polyMesh/blockMeshDict"
     controlDict="system/controlDict"
+
     sed \
     -e s/"23 8"/"46 10"/g \
     -e s/"19 8"/"40 10"/g \
@@ -17,6 +20,7 @@ setDamBreakFine ()
     -e s/"19 42\(.*\) 1 1)"/"40 76\1 2 1)"/g \
     $blockMeshDict > temp.$$
     mv temp.$$ $blockMeshDict
+
     sed \
     -e s/"\(deltaT[ \t]*\) 0.001;"/"\1 5e-04;"/g \
     -e s/"\(endTime[ \t]*\) 1;"/"\1 0.4;"/g \
@@ -25,19 +29,24 @@ setDamBreakFine ()
 }
 
 # Do damBreak
-(cd damBreak && foamRunTutorials)
+( cd damBreak && foamRunTutorials )
 
 # Clone case
 cloneCase damBreak damBreakFine
 
-cd damBreakFine
+(
+    cd damBreakFine || exit
+
     # Modify case
     setDamBreakFine
     cp ../damBreak/0/alpha1.org 0/alpha1
+
     # And execute
     runApplication blockMesh
     runApplication setFields
     runApplication decomposePar
     runParallel $application 4
     runApplication reconstructPar
-cd ..
+)
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interFoam/ras/damBreak/Allrun b/tutorials/multiphase/interFoam/ras/damBreak/Allrun
index 90917ec79581d50caa94e093fdaa403d30cc1032..31c6c104c4d08b1bfe261de4868820bb191338cd 100755
--- a/tutorials/multiphase/interFoam/ras/damBreak/Allrun
+++ b/tutorials/multiphase/interFoam/ras/damBreak/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ application=`getApplication`
 runApplication blockMesh
 runApplication setFields
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allclean b/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allclean
index cff4dbd23191f6a4ca343bf6898b0762ed0cce6d..ec47d1656a4cec01ae52e8ef5a5c7363a249856d 100755
--- a/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allclean
+++ b/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allclean
@@ -1,4 +1,7 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 foamCleanTutorials cases
 rm -rf 0/alpha[1-3].gz
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allrun b/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allrun
index 15f6fafd90d19159e7c83d7192668c297d0e6798..ea8cb0136a91ab67b953d6d252039e1864c2d499 100755
--- a/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allrun
+++ b/tutorials/multiphase/interMixingFoam/laminar/damBreak/Allrun
@@ -1,4 +1,6 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
@@ -8,3 +10,5 @@ cp 0/alpha2.org 0/alpha2
 cp 0/alpha3.org 0/alpha3
 runApplication setFields
 runApplication interMixingFoam
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun b/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun
index 849b5fd3e72d6f38c58a86024be5edc634d0bdbf..019100e5d8e624b6a736a018964b1f910432efe1 100755
--- a/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun
+++ b/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -12,3 +13,4 @@ runApplication snappyHexMesh -overwrite
 # Run the solver
 runApplication interPhaseChangeFoam
 
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/settlingFoam/ras/tank3D/Allclean b/tutorials/multiphase/settlingFoam/ras/tank3D/Allclean
index 35e38c65c54b6620f679d4494c76cc03f97cdd57..e0102f95da61148486642f2d11c341c043e6a4fe 100755
--- a/tutorials/multiphase/settlingFoam/ras/tank3D/Allclean
+++ b/tutorials/multiphase/settlingFoam/ras/tank3D/Allclean
@@ -1,6 +1,9 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Clean time folders only
 
 rm -rf *[1-9]*
 rm -f log.* 2>/dev/null
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/settlingFoam/ras/tank3D/Allrun b/tutorials/multiphase/settlingFoam/ras/tank3D/Allrun
index 411704d7836a4f61312e668b2f93d4ae057a8e22..581f44483939f4932fc1109584308429c983a99d 100755
--- a/tutorials/multiphase/settlingFoam/ras/tank3D/Allrun
+++ b/tutorials/multiphase/settlingFoam/ras/tank3D/Allrun
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
 
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
@@ -6,3 +7,5 @@
 application=`getApplication`
 
 runApplication $application
+
+# ----------------------------------------------------------------- end-of-file