Commit 7f01a4be authored by Mark Olesen's avatar Mark Olesen
Browse files

CONFIG: address differences between shells

- suppress error messages that appear with zsh.
  According to unset(1p), 'unset -f' unsets a function.
  If the function was not previously defined, this is a no-op.
  This is similar for zsh, but there it emits a warning if the
  function was not previously defined.

- avoid 'local' in functions sources from etc/bashrc.
  ksh does not support this.

- use 'command' shell builtin instead of 'type'.
  Seems to be more consistent between shell flavours.
parent 765c4307
......@@ -27,7 +27,7 @@
# Description
# Set the environment for OpenFOAM when using a POSIX shell.
# To be sourced manually or from the ~/.profile or ~/.bashrc files.
# Should be usable by any POSIX-compliant shell (eg, dash, ksh)
# Should be usable by any POSIX-compliant shell (eg, bash,dash,zsh,...)
#
#------------------------------------------------------------------------------
......
......@@ -68,6 +68,6 @@ if ( "$ending" != "adios-none" && "$ending" != "adios-system" ) then
_foamAddPath $ADIOS_ARCH_PATH/bin
endif
unset adios_version ending cleaned
unset adios_version ending
#------------------------------------------------------------------------------
......@@ -167,8 +167,6 @@ if ( $?foamClean ) then
endif
unset cleaned foamClean foamOldDirs
#------------------------------------------------------------------------------
# Cleanup aliases
......@@ -198,5 +196,9 @@ unalias wmRefresh
unalias foamVersion
unalias foamPV
#------------------------------------------------------------------------------
# Intermediate variables (do as last for a clean exit code)
unset cleaned foamClean foamOldDirs
#------------------------------------------------------------------------------
......@@ -58,7 +58,7 @@ then
echo "Using adios ($adios_version) -> $ADIOS_ARCH_PATH" 1>&2
fi
if type _foamAddPath > /dev/null 2>&1 # normal sourcing
if command -v _foamAddPath >/dev/null 2>&1 # normal sourcing
then
# If ADIOS_ARCH_PATH does not end with '-system' or '-none',
# it is located within ThirdParty, or a central installation
......@@ -71,7 +71,7 @@ then
_foamAddPath $ADIOS_ARCH_PATH/bin
fi
unset adios_version ending cleaned
unset adios_version ending
fi
......
......@@ -64,7 +64,7 @@ then
echo "Using CGAL ($cgal_version) -> $CGAL_ARCH_PATH" 1>&2
fi
if type _foamAddLib > /dev/null 2>&1 # normal sourcing
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
# If BOOST_ARCH_PATH, CGAL_ARCH_PATH do not end with '-system' or '-none',
......
......@@ -58,7 +58,7 @@ then
echo "Using fftw ($fftw_version) -> $FFTW_ARCH_PATH" 1>&2
fi
if type _foamAddLib > /dev/null 2>&1 # normal sourcing
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
# If FFTW_ARCH_PATH does not end with '-system' or '-none',
......
......@@ -69,7 +69,7 @@ alias run='cd $FOAM_RUN'
# Refresh the environment
# ~~~~~~~~~~~~~~~~~~~~~~~
unset -f wmRefresh
unset -f wmRefresh 2>/dev/null
wmRefresh()
{
wmProjectDir=$WM_PROJECT_DIR
......@@ -81,7 +81,7 @@ wmRefresh()
# Change OpenFOAM version
# ~~~~~~~~~~~~~~~~~~~~~~~
unset -f foamVersion
unset -f foamVersion 2>/dev/null
foamVersion()
{
if [ "$1" ]; then
......@@ -98,7 +98,7 @@ foamVersion()
# Change ParaView version
# ~~~~~~~~~~~~~~~~~~~~~~~
unset -f foamPV
unset -f foamPV 2>/dev/null
foamPV()
{
. $WM_PROJECT_DIR/etc/config.sh/paraview "${@+ParaView_VERSION=$1}"
......
......@@ -56,15 +56,13 @@ then
}
# Source an etc file, possibly with some verbosity
_foamEtc()
{
local file
if [ $# -gt 0 ] && file=$($WM_PROJECT_DIR/bin/foamEtcFile "$@")
then
[ "$FOAM_VERBOSE" -a "$PS1" ] && echo "Using: $file" 1>&2
. $file
fi
}
# - use eval to avoid intermediate variables (ksh doesn't have 'local')
if [ "$FOAM_VERBOSE" -a "$PS1" ]
then
_foamEtc(){ eval "$($WM_PROJECT_DIR/bin/foamEtcFile -sh-verbose $@)"; }
else
_foamEtc(){ eval "$($WM_PROJECT_DIR/bin/foamEtcFile -sh $@)"; }
fi
# Evaluate command-line parameters
_foamEval()
......@@ -104,9 +102,9 @@ then
else
# Was previously loaded/defined - now unset
unset -f _foamAddPath _foamAddLib _foamAddMan 2>/dev/null
unset -f _foamEtc _foamEval 2>/dev/null
unset WM_SHELL_FUNCTIONS
unset -f _foamAddPath _foamAddLib _foamAddMan
unset -f _foamEtc _foamEval
fi
......
......@@ -58,7 +58,7 @@ then
echo "Using gperftools ($gperftools_version) -> $GPERFTOOLS_ARCH_PATH" 1>&2
fi
if type _foamAddLib > /dev/null 2>&1 # normal sourcing
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
# If GPERFTOOLS_ARCH_PATH does not end with '-system' or '-none',
......
......@@ -71,7 +71,7 @@ OPENMPI)
fi
# Could be sourced from ThirdParty with incomplete environment
if type _foamAddLib > /dev/null 2>&1
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
_foamAddPath $MPI_ARCH_PATH/bin
_foamAddLib $MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
......@@ -140,7 +140,7 @@ MPICH)
export MPI_HOME=$MPI_ARCH_PATH
# Could be sourced from ThirdParty with incomplete environment
if type _foamAddLib > /dev/null 2>&1
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
_foamAddPath $MPI_ARCH_PATH/bin
_foamAddLib $MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
......
......@@ -173,7 +173,7 @@ unset -f _foamParaviewEval
unset cleaned cmake cmake_version pvName pvMajor pvLibDir pvPython
unset ParaView_MAJOR
if type _foamAddLib > /dev/null 2>&1 # normal sourcing
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
unset ParaView_VERSION
fi
......
......@@ -148,13 +148,9 @@ then
cleaned=$($foamClean "$MANPATH" "$foamOldDirs") && MANPATH="$cleaned"
fi
[ -n "$LD_LIBRARY_PATH" ] || unset LD_LIBRARY_PATH
[ -n "$MANPATH" ] || unset MANPATH
[ -n "$LD_PRELOAD" ] || unset LD_PRELOAD
unset cleaned foamClean foamOldDirs
[ -n "$MANPATH" ] || unset MANPATH
#------------------------------------------------------------------------------
# Cleanup aliases and functions
......@@ -181,9 +177,13 @@ unalias util 2>/dev/null
unalias tut 2>/dev/null
unalias run 2>/dev/null
unset -f wmRefresh
unset -f foamVersion
unset -f foamPV
unset -f wmRefresh 2>/dev/null
unset -f foamVersion 2>/dev/null
unset -f foamPV 2>/dev/null
#------------------------------------------------------------------------------
# Intermediate variables (do as last for a clean exit code)
unset cleaned foamClean foamOldDirs
#------------------------------------------------------------------------------
......@@ -57,7 +57,7 @@ then
echo "Using mesa ($mesa_version) -> $MESA_ARCH_PATH" 1>&2
fi
if type _foamAddLib > /dev/null 2>&1 # normal sourcing
if command -v _foamAddLib > /dev/null 2>&1 # normal sourcing
then
# Set paths if binaries are present
......
......@@ -145,7 +145,7 @@ endif
# ~~~~~~~~~~~~~~~~~~~~~~
setenv WM_PROJECT_USER_DIR $HOME/$WM_PROJECT/$LOGNAME-$WM_PROJECT_VERSION
# Source etc files, possibly with some verbosity
# Source an etc file, possibly with some verbosity
if ($?FOAM_VERBOSE && $?prompt) then
alias _foamEtc 'eval `$WM_PROJECT_DIR/bin/foamEtcFile -csh-verbose \!*`'
else
......
......@@ -158,7 +158,7 @@ canBuildPlugin()
return 1
}
type cmake > /dev/null 2>&1 || {
command -v cmake > /dev/null 2>&1 || {
echo "==> cannot build ParaView plugins without cmake"
return 1
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment