From 695716d5ccc314e19d09650b3deeafb723b5eaf3 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 9 Aug 2017 11:58:43 +0200
Subject: [PATCH] STYLE: use local variables in aliases/functions

---
 etc/config.sh/aliases | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/etc/config.sh/aliases b/etc/config.sh/aliases
index 23b8b636e80..0543a09a708 100644
--- a/etc/config.sh/aliases
+++ b/etc/config.sh/aliases
@@ -72,10 +72,10 @@ alias run='cd $FOAM_RUN'
 unset -f wmRefresh 2>/dev/null
 wmRefresh()
 {
-    wmProjectDir=$WM_PROJECT_DIR
-    foamSettings=$FOAM_SETTINGS
+    local projectDir=$WM_PROJECT_DIR
+    local foamSettings=$FOAM_SETTINGS
     wmUnset
-    . $wmProjectDir/etc/bashrc $foamSettings
+    . $projectDir/etc/bashrc $foamSettings
 }
 
 
@@ -84,12 +84,25 @@ wmRefresh()
 unset -f foamVersion 2>/dev/null
 foamVersion()
 {
-    if [ "$1" ]; then
+    if [ "$#" -gt 0 ]
+    then
+        local ver=$1
+        shift
+        # The variable foamInstDir had meaning for older OpenFOAM versions
         foamInstDir=$FOAM_INST_DIR
-        wmUnset
-        . $foamInstDir/OpenFOAM-$1/etc/bashrc
-        foam
-        echo "Changed to OpenFOAM-$1" 1>&2
+        if [ -f "$foamInstDir/OpenFOAM-$ver/etc/bashrc" ]
+        then
+            wmUnset
+            . $foamInstDir/OpenFOAM-$ver/etc/bashrc
+            unset foamInstDir
+            foam
+            echo "Changed to OpenFOAM-$WM_PROJECT_VERSION" 1>&2
+        else
+            unset foamInstDir
+            echo "No OpenFOAM-$ver available" 1>&2
+            echo "Using OpenFOAM-$WM_PROJECT_VERSION" 1>&2
+            return 1
+        fi
     else
         echo "OpenFOAM-$WM_PROJECT_VERSION" 1>&2
     fi
-- 
GitLab