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.
This commit is contained in:
Mark Olesen 2016-10-28 16:48:30 +02:00
parent 00939bcba9
commit b844867112

View File

@ -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,