From f1d03a3802075076d56e53d5235a523874c4b27c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 23 Mar 2010 14:05:51 +0100 Subject: [PATCH] ENH: cleanup shell scripts, BUG: unclosed 'if' in inlineReplace --- bin/foamEtcFile | 16 ++++++++-------- bin/foamRunTutorials | 14 +++++++------- bin/foamTags | 4 ++-- bin/rm~all | 2 +- bin/tools/inlineReplace | 27 +++++++++++++-------------- wmake/wmakeLnInclude | 30 ++++++++++++++---------------- 6 files changed, 45 insertions(+), 48 deletions(-) diff --git a/bin/foamEtcFile b/bin/foamEtcFile index b749a76e97..9b43222de4 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -30,7 +30,7 @@ # Locate user/group/shipped file with semantics similar to the # ~OpenFOAM/fileName expansion. # -# The -mode option can be used to allow chaining from +# The -mode option can be used to allow chaining from # personal settings to site-wide settings. # # For example, within the user ~/.OpenFOAM//prefs.sh: @@ -119,27 +119,27 @@ nArgs=$# fileName="$1" # Define the various places to be searched: -files="" +unset dirList case "$mode" in *u*) # user - files="$files $HOME/.${WM_PROJECT:-OpenFOAM}/$WM_PROJECT_VERSION" - files="$files $HOME/.${WM_PROJECT:-OpenFOAM}" + dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}/$WM_PROJECT_VERSION" + dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}" ;; esac case "$mode" in *g*) # group - files="$files $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION" - files="$files $WM_PROJECT_INST_DIR/site" + dirList="$dirList $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION" + dirList="$dirList $WM_PROJECT_INST_DIR/site" ;; esac case "$mode" in *o*) # other - files="$files $WM_PROJECT_DIR/etc" + dirList="$dirList $WM_PROJECT_DIR/etc" ;; esac -set -- $files +set -- $dirList # diff --git a/bin/foamRunTutorials b/bin/foamRunTutorials index 7c52b6b9e1..2d0c8f7a71 100755 --- a/bin/foamRunTutorials +++ b/bin/foamRunTutorials @@ -46,7 +46,7 @@ if [ $# = 0 -a -f "./Allrun" ] then # Specialised script. ./Allrun -elif [ -d "./system" ] +elif [ -d system ] then # Normal case. parentDir=`dirname $PWD` @@ -55,19 +55,19 @@ then runApplication $application else # Loop over sub-directories and compile any applications - for case in * + for caseName in * do - if [ -d $case -a -d "$case/Make" ] + if [ -d $caseName -a -d "$caseName/Make" ] then - (compileApplication $case) + ( compileApplication $caseName ) fi done # Recurse to subdirectories - for case in * + for caseName in * do - if [ -d $case ] + if [ -d $caseName ] then - (cd $case && $thisScript) + ( cd $caseName && $thisScript ) fi done fi diff --git a/bin/foamTags b/bin/foamTags index 18ad697768..3331c16bf2 100755 --- a/bin/foamTags +++ b/bin/foamTags @@ -45,12 +45,12 @@ for cmd in etags ectags do type $cmd >/dev/null 2>&1 || { echo "${0##*/} cannot build tag files: '$cmd' command not found" - exit + exit 1 } done -cd $WM_PROJECT_DIR || exit +cd $WM_PROJECT_DIR || exit 1 mkdir .tags 2>/dev/null diff --git a/bin/rm~all b/bin/rm~all index afc658b76b..6d53ec55a2 100755 --- a/bin/rm~all +++ b/bin/rm~all @@ -49,7 +49,7 @@ do echo "removing all *~ files: $i" find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm 2>/dev/null else - echo "no directory: $i" 1>&2 + echo "no directory: $i" 1>&2 fi done diff --git a/bin/tools/inlineReplace b/bin/tools/inlineReplace index 4e502bccb2..27d19f8164 100755 --- a/bin/tools/inlineReplace +++ b/bin/tools/inlineReplace @@ -1,31 +1,30 @@ #!/bin/sh -# $0 string1 string2 file1 .. filen +# $0 oldString newString file1 .. fileN # if [ $# -lt 3 ] then - echo "Usage: ${0##*/} [-f] .. " + echo "Usage: ${0##*/} [.. 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)" + echo "Replaces all occurrences of oldString by newString in files." + echo "(replacement for sed -i on systems that don't support it)" exit 1 fi -FROMSTRING=$1 -shift -TOSTRING=$1 -shift +oldString="$1" +newString="$2" +shift 2 -for f in $* +for f do - if grep "$FROMSTRING" "$f" >/dev/null + if grep "$oldString" "$f" >/dev/null then cp "$f" "${f}_bak" - sed -e "s@$FROMSTRING@$TOSTRING@g" "${f}"_bak > "$f" - rm -f "${f}"_bak + sed -e "s@$oldString@$newString@g" "${f}_bak" > "$f" + rm -f "${f}_bak" #else - # echo "String $FROMSTRING not present in $f" - #fi + # echo "String $oldString not present in $f" + fi done # ----------------------------------------------------------------- end-of-file diff --git a/wmake/wmakeLnInclude b/wmake/wmakeLnInclude index 0580893b76..820acf91a4 100755 --- a/wmake/wmakeLnInclude +++ b/wmake/wmakeLnInclude @@ -3,7 +3,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | -# \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. +# \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. # \\/ M anipulation | #------------------------------------------------------------------------------- # License @@ -58,13 +58,14 @@ USAGE #------------------------------------------------------------------------------ -# simple option parsing -unset forceUpdate +# default 'find' option unset findOpt -# default ln option +# default 'ln' option lnOpt="-s" +unset forceUpdate + # simple parse options while [ "$#" -gt 0 ] do @@ -74,7 +75,7 @@ do ;; -f) shift - forceUpdate=1 + forceUpdate=true lnOpt="-sf" ;; -*) @@ -110,28 +111,25 @@ done incDir=$baseDir/lnInclude -if [ ! -d $baseDir ] -then +[ -d $baseDir ] || { echo "$Script error: base directory $baseDir does not exist" 1>&2 exit 2 -fi +} if [ -d $incDir ] then - if [ ! "$forceUpdate" ] - then - # echo "$Script error: include directory $incDir already exists" 1>&2 - exit 0 - fi + [ "$forceUpdate" = true ] || { + # echo "$Script error: include directory $incDir already exists" 1>&2 + exit 0 + } else mkdir $incDir fi -if [ ! -d $incDir ] -then +[ -d $incDir ] || { echo "$Script error: failed to create include directory $incDir" 1>&2 exit 0 -fi +} cd $incDir || exit 1