Tuesday, August 26, 2014

Newer Workaround for set -e Bug in bash with RVM

Just found out that with the newer RVM (noticed in v1.25.28 and 29 (stable) but not sure which versions are affected), the old fix that we used in our bash script:

# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"
  printf "ERROR: An RVM installation was not found.\n"

That allowed use of so that RVM wouldn't break when using both set -e and cd'ing into a project directory that has a .ruby-version/.ruby-gemset:

set -e
cd /some/path/to/project

Will now break the script, exiting when you call the cd command (issue #3017).

The workaround provided by Michal Papis is to use the builtin cd and rvm use instead which seems to work:

set -e
builtin cd /some/path/to/project
rvm use .

Edited 2014-09-04 to provide solution from Michal Papis.

No comments: