diff --git a/bin/foamTestTutorial b/bin/foamTestTutorial index a2e94a217a..a10d6bd05d 100755 --- a/bin/foamTestTutorial +++ b/bin/foamTestTutorial @@ -151,10 +151,10 @@ modifyCaseControlDict() do cp -f "${dict}" "${dict}.orig" sed \ - -e 's/\(startFrom[ \t]*\)\([A-Za-z]*\);/\1 latestTime;/' \ - -e 's/\(stopAt[ \t]*\)\([A-Za-z]*\);/\1 nextWrite;/' \ - -e 's/\(writeControl[ \t]*\)\([A-Za-z]*\);/\1 timeStep;/' \ - -e 's/\(writeInterval[ \t]*\)\([-.0-9A-Za-z]*\);/\1 '"$optRunLimit"';/' \ + -e 's/\(startFrom[ \t]*\)[^ \t;]*;/\1 latestTime;/' \ + -e 's/\(stopAt[ \t]*\)[^ \t;]*;/\1 nextWrite;/' \ + -e 's/\(writeControl[ \t]*\)[^ \t;]*;/\1 timeStep;/' \ + -e 's/\(writeInterval[ \t]*\)[^ \t;]*;/\1 '"${optRunLimit:-1}"';/' \ "${dict}.orig" > "${dict}" done } diff --git a/bin/tools/openfoam.in b/bin/tools/openfoam.in index d712512d0c..5676d240d7 100644 --- a/bin/tools/openfoam.in +++ b/bin/tools/openfoam.in @@ -1,19 +1,13 @@ #!/bin/sh exec "@PROJECT_DIR@"/etc/openfoam "$@" #------------------------------------------------------------------------------ -# ========= | -# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox -# \\ / O peration | -# \\ / A nd | www.openfoam.com -# \\/ M anipulation | -#------------------------------------------------------------------------------ -# Copyright (C) 2020 OpenCFD Ltd. -#------------------------------------------------------------------------------ -# License -# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# OpenFOAM file (www.openfoam.com) +# +# Copyright (C) 2020-2021 OpenCFD Ltd. +# SPDX-License-Identifier: (GPL-3.0+) # # Description -# Forwarding to OpenFOAM etc/openfoam bash session script. -# Uses a hard-code directory path (eg, generated with autoconfig). +# Forward to OpenFOAM etc/openfoam bash session script. +# Uses hard-coded directory path. # #------------------------------------------------------------------------------ diff --git a/etc/config.csh/setup b/etc/config.csh/setup index 070233ddc8..a852c9461d 100644 --- a/etc/config.csh/setup +++ b/etc/config.csh/setup @@ -5,7 +5,7 @@ # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ -# Copyright (C) 2018-2020 OpenCFD Ltd. +# Copyright (C) 2018-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -105,7 +105,10 @@ while ( $#argv > 0 ) switch ($argv[1]) case -*: # Stray option (not meant for us here) -> get out - break + break # Break while + breaksw + case =*: + # Junk breaksw case *=: # name= -> unsetenv name diff --git a/etc/config.sh/functions b/etc/config.sh/functions index 9c55f5cdd8..5945ba8bde 100644 --- a/etc/config.sh/functions +++ b/etc/config.sh/functions @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2017-2020 OpenCFD Ltd. +# Copyright (C) 2017-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -159,45 +159,6 @@ then fi - # Evaluate command-line parameters - unset -f _foamEval 2>/dev/null - _foamEval() - { - for i - do - case "$i" in - -*) - # Stray option (not meant for us here) -> get out - break - ;; - *=) - # name= -> unset name - [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \ - && echo "unset ${1%=}" 1>&2 - eval "unset ${1%=}" - ;; - *=*) - # name=value -> export name=value - [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \ - && echo "export $i" 1>&2 - eval "export $i" - ;; - *) - # Filename: source it - if [ -f "$i" ] - then - [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \ - && echo "Using: $i" 1>&2 - . "$i" - else - _foamEtc -silent "$i" - fi - ;; - esac - done - } - - #-------------------------------------------------------------------------- # Avoid any ThirdParty settings that may have 'leaked' into the environment @@ -221,7 +182,7 @@ else # Was previously loaded/defined - now unset unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null - unset -f _foamClean _foamEcho _foamEtc _foamEval 2>/dev/null + unset -f _foamClean _foamEcho _foamEtc 2>/dev/null unset foamClean unset WM_SHELL_FUNCTIONS diff --git a/etc/config.sh/setup b/etc/config.sh/setup index b5adaa08f8..a5440df6f4 100644 --- a/etc/config.sh/setup +++ b/etc/config.sh/setup @@ -5,7 +5,7 @@ # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ -# Copyright (C) 2018-2020 OpenCFD Ltd. +# Copyright (C) 2018-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -106,19 +106,64 @@ then fi -# Capture and evaluate any command-line parameters -# These can be used to set/unset values, specify additional files etc. -FOAM_SETTINGS="$@" +#---------------------------------------------------------------------------- -# Evaluate the command-line parameters, which were saved as FOAM_SETTINGS. -# These can be used to set/unset values, specify additional files etc. -if [ -z "$FOAM_SETTINGS" ] +# Capture and evaluate command-line parameters +# - set/unset values, specify additional files etc. +# - parameters never start with '-' +if [ "$#" -gt 0 ] && [ "${1#-}" = "${1}" ] then - unset FOAM_SETTINGS + FOAM_SETTINGS="$@" + if [ -n "$FOAM_SETTINGS" ] + then + export FOAM_SETTINGS + + for foamVar_eval + do + case "$foamVar_eval" in + (-*) + # Stray option (not meant for us here) -> get out + break + ;; + (=*) + # Junk + ;; + (*=) + # name= -> unset name + [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \ + && echo "unset ${foamVar_eval%=}" 1>&2 + eval "unset ${foamVar_eval%=}" + ;; + (*=*) + # name=value -> export name=value + [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \ + && echo "export $foamVar_eval" 1>&2 + eval "export $foamVar_eval" + ;; + (*) + # Filename: source it + if [ -f "$foamVar_eval" ] + then + [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \ + && echo "Using: $foamVar_eval" 1>&2 + . "$foamVar_eval" + elif [ -n "$foamVar_eval" ] + then + _foamEtc -silent "$foamVar_eval" + fi + ;; + esac + done + else + unset FOAM_SETTINGS + fi else - export FOAM_SETTINGS - _foamEval "$@" + unset FOAM_SETTINGS fi +unset foamVar_eval + + +#---------------------------------------------------------------------------- # Verify FOAM_CONFIG_ETC (from calling environment or from prefs) if [ -n "$FOAM_CONFIG_ETC" ] diff --git a/etc/openfoam b/etc/openfoam index 87191ad716..7a29ff2b44 100755 --- a/etc/openfoam +++ b/etc/openfoam @@ -31,7 +31,7 @@ # -int32 | -DWM_LABEL_SIZE=32 # -int64 | -DWM_LABEL_SIZE=64 # -# However, the '-D' options grant more flexibility. For example, +# The '-D' options grant even more flexibility. For example, # etc/openfoam -DWM_COMPILER=Clang # # SeeAlso @@ -43,26 +43,30 @@ projectDir="$(\cd "$(dirname "${0%/*}")" && \pwd -L)" #------------------------------------------------------------------------------ printHelp() { - cat<&2 - exit 1 - } - shift 2 - break + (-c) # Shell command + _foamScriptCommand="-c" ;; -D*) # Define key/value to pass as preference @@ -175,11 +178,6 @@ do -verbose) export FOAM_VERBOSE=true ;; - - --) - shift - break - ;; -*) echo "$0: unknown option: '$1'" 1>&2 exit 1 @@ -217,7 +215,14 @@ fi unset interactive -if [ "$#" -eq 0 ] && [ -z "$_foamScriptCommand" ] && [ -z "$optTestTut" ] +if [ -n "$_foamScriptCommand" ] +then + if [ "$#" -eq 0 ] + then + echo "$0: -c: option requires an argument" 1>&2 + exit 1 + fi +elif [ "$#" -eq 0 ] && [ -z "$optTestTut" ] then interactive=true fi @@ -283,16 +288,14 @@ sourceBashrc() if [ -n "$_foamScriptCommand" ] then # A shell command - sourceBashrc - exec bash -c "$_foamScriptCommand" "$@" + exec bash -c "$@" exit $? # Safety fi - if [ -n "$optTestTut" ] then - + # Test tutorial(s) sourceBashrc exec "$WM_PROJECT_DIR"/bin/foamTestTutorial "$@" exit $? # Safety diff --git a/tutorials/Alltest b/tutorials/Alltest index 7339b01ae1..847c2dc778 100755 --- a/tutorials/Alltest +++ b/tutorials/Alltest @@ -71,7 +71,7 @@ while [ "$#" -gt 0 ] do case "$1" in -h* | -help*) printHelp ;; - -f | -force) optForce=true ;; + -f | -force) optForce=true ;; -root=*) rootDir="${1#*=}" @@ -148,10 +148,10 @@ modifyCaseControlDict() do cp -f "${dict}" "${dict}.orig" sed \ - -e 's/\(startFrom[ \t]*\)\([A-Za-z]*\);/\1 latestTime;/' \ - -e 's/\(stopAt[ \t]*\)\([A-Za-z]*\);/\1 nextWrite;/' \ - -e 's/\(writeControl[ \t]*\)\([A-Za-z]*\);/\1 timeStep;/' \ - -e 's/\(writeInterval[ \t]*\)\([-.0-9A-Za-z]*\);/\1 '"$optRunLimit"';/' \ + -e 's/\(startFrom[ \t]*\)[^ \t;]*;/\1 latestTime;/' \ + -e 's/\(stopAt[ \t]*\)[^ \t;]*;/\1 nextWrite;/' \ + -e 's/\(writeControl[ \t]*\)[^ \t;]*;/\1 timeStep;/' \ + -e 's/\(writeInterval[ \t]*\)[^ \t;]*;/\1 '"${optRunLimit:-1}"';/' \ "${dict}.orig" > "${dict}" done }