View Issue Details

IDProjectCategoryView StatusLast Update
0002310OpenFOAMPatchpublic2019-07-16 14:45
ReporterwyldckatAssigned Tohenry 
PrioritylowSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Fixed in Version 
Summary0002310: Sourcing etc/bashrc locally leads to problems
DescriptionAlthough several installation instructions refer to using the complete path when sourcing OpenFOAM's "etc/bashrc" file, long time users of OpenFOAM technology will more often than not use:

  source etc/bashrc

This happened to me a few weeks ago, but I worked around it by running:

  source $PWD/etc/bashrc

The problem is that the following script code in said file assumes the whole path is given and has no check for failure and subsequent bypass:

  export FOAM_INST_DIR=$(cd ${BASH_SOURCE%/*/*/*} && pwd -P)

The tricky part now is that there are a few workarounds for generalization, but each has their own flaws:

  Hypothesis 1:

    export FOAM_INST_DIR=$(cd ${BASH_SOURCE%/*} && cd ../.. && pwd -P)

  Fails when we source from inside:

    source bashrc


  Hypothesis 2:

    export FOAM_INST_DIR=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P)

  Fails if "dirname" doesn't exist, relies on two sub-shells (small hit to performance?), but it's the most common solution found online, e.g.:

    - http://unix.stackexchange.com/a/216915
    - http://stackoverflow.com/a/246128

  Although most of them actually use "${BASH_SOURCE[0]}", which seems a bit strange... although that's what the manual indicates: https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fSOURCE - i.e. it's an array.


  Hypothesis 3:

    Based on hypothesis #2, use 5-7 lines of code that checks if everything goes smoothly and handles things properly in case of failure.

    Given this seems like overkill, at least for now, I've disregarded this hypothesis.


All of these hypothesis will fail due if the environment variable "CDPATH" gets in the way... but that's for another documentation-feature request, since it's along the lines of aliases breaking scripts.


Either way, I'm attaching the updated scripts for 4.x and dev which use hypothesis #2:

  - "bashrc.v4" for "OpenFOAM-4.x/etc/bashrc"
  - "bashrc.dev" for "OpenFOAM-dev/etc/bashrc"
TagsNo tags attached.

Relationships

related to 0003303 resolvedhenry Compilation of (Intel) MPI fails 

Activities

wyldckat

2016-10-29 21:36

updater  

bashrc.v4 (6,866 bytes)

wyldckat

2016-10-29 21:36

updater  

bashrc.dev (6,817 bytes)

henry

2016-11-04 13:29

manager   ~0007089

Thanks Bruno

Resolved in OpenFOAM-4.x by commit 423ac54eabed1a9df7cd906686a8499f4cf69719

Resolved in OpenFOAM-dev by commit cfcd1adacb3706ae667b013035edbbaa7a37e0a4

Issue History

Date Modified Username Field Change
2016-10-29 21:36 wyldckat New Issue
2016-10-29 21:36 wyldckat Status new => assigned
2016-10-29 21:36 wyldckat Assigned To => henry
2016-10-29 21:36 wyldckat File Added: bashrc.v4
2016-10-29 21:36 wyldckat File Added: bashrc.dev
2016-11-04 13:29 henry Status assigned => resolved
2016-11-04 13:29 henry Resolution open => fixed
2016-11-04 13:29 henry Fixed in Version => 4.x
2016-11-04 13:29 henry Note Added: 0007089
2019-07-16 14:45 henry Relationship added related to 0003303