From b8448671125c506b044dc05896d94a7a336c87fb Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 28 Oct 2016 16:48:30 +0200 Subject: [PATCH] BUG: etc/bashrc incorrect behaviour if sourced locally (issue #280) - It is incorrect to prefix the assignment with an 'export' since this automatically marks the overall command as successful and circumvents the fallback. There is no simple way to have proper behaviour when sourced with a local directory path, but at least it now uses the fallback. It is still easy to wreak the mechanism with valid but confusing input. For example, ". /path/to/openfoam/etc/././bashrc" The only real certainty is that "${BASH_SOURCE%/*}" should point to the 'etc/' directory. In which case, cd ${BASH_SOURCE%/*} # <- now in the etc/ directory pwd=$(pwd -P) # <- fully-qualified path to etc/ pwd=${pwd%/*/*} # <- up two parent levels - This works with ". ./bashrc", but fails with ". bashrc" (probably not so common). - Con: The construct requires an additional sub-shell. --- etc/bashrc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/bashrc b/etc/bashrc index 01115f2600a..c65f5fab04b 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -42,15 +42,15 @@ export WM_PROJECT_VERSION=plus # # Please set to the appropriate path if the default is not correct. # -[ $BASH_SOURCE ] && \ -export FOAM_INST_DIR=$(\cd ${BASH_SOURCE%/*/*/*} && pwd -P) || \ -export FOAM_INST_DIR=$HOME/$WM_PROJECT -# export FOAM_INST_DIR=~$WM_PROJECT -# export FOAM_INST_DIR=/opt/$WM_PROJECT -# export FOAM_INST_DIR=/usr/local/$WM_PROJECT +[ $BASH_SOURCE ] && FOAM_INST_DIR=$(\cd ${BASH_SOURCE%/*/*/*} && \pwd -P) || \ +FOAM_INST_DIR=$HOME/$WM_PROJECT +# FOAM_INST_DIR=~$WM_PROJECT +# FOAM_INST_DIR=/opt/$WM_PROJECT +# FOAM_INST_DIR=/usr/local/$WM_PROJECT # # END OF (NORMAL) USER EDITABLE PART ################################################################################ +export FOAM_INST_DIR # The default environment variables below can be overridden in a prefs.sh file # located in ~/.OpenFOAM/$WM_PROJECT_VERSION, ~/.OpenFOAM, -- GitLab