Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to write a script that does goes through all the steps for installing and setting up a graylog2 server and web interface on CentOS 6.2. Here is the section that I'm having trouble with:

curl -L get.rvm.io | bash -s stable
# 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"

else

  printf "ERROR: An RVM installation was not found.\n"

fi

rvm install 1.9.3 --create
rvm use 1.9.3 --default

So when it tries to load the rvm function into the shell as a function, it won't work, causing it to not install ruby. I've tried other methods of loading the function into the shell, as follows:

Manually sourcing the scripts file from a root install

source /usr/local/rvm/scripts/rvm

Manually adding the PATH environment variable to include rvm:

PATH=$PATH:/usr/local/rvm/bin
export PATH

Manually calling the path to the rvm command

/usr/local/rvm/bin/rvm install 1.9.3 --create

Sourcing /etc/profile.d/rvm.sh

source /etc/profile.d/rvm.sh

Note that if I do close out of the shell and log back in, rvm loads just fine, but I need to be able to do it all from within this script without having to log out and log back in. I'm also doing this from as root. You can look at the script I've written so far in it's entirety here.

Any help is appreciated.

EDIT

After adding set -x to the script, here is the output when it tries to load the function:

+ [[ -s /root/.rvm/scripts/rvm ]]
+ [[ -s /usr/local/rvm/scripts/rvm ]]
+ source /usr/local/rvm/scripts/rvm
++ [[ :braceexpand:hashall:interactive-comments:posix:xtrace: =~ :posix: ]]
++ return 0
+ rvm install 1.9.3 --create
./rvm_test.sh: line 27: rvm: command not found
+ rvm use 1.9.3 --default
./rvm_test.sh: line 28: rvm: command not found

EDIT 2

I looked into the /usr/local/rvm/scripts/rvm file and found this at the very beginning:

# Do not allow sourcing RVM in `sh` - it's not supported
# return 0 to exit from sourcing this script without breaking sh
[[ ":$SHELLOPTS:" =~ ":posix:" ]] && return 0 || true

So I believe this is causing the my problem but I'm not sure. I'm not experienced in bash scripting :\ So the problem I'm guessing is that my shell isn't supported(?) can anybody clarify?

share|improve this question
    
Add a line with set -x in the beginning of the script to see how all the variables are expanded and why tests return false. Are you aware of that if you are running as root, the $HOME variable will give /root? –  Daniel Andersson Apr 12 '12 at 18:15
    
added the output after adding set -x @DanielAndersson –  Robert Horn Apr 13 '12 at 14:04
    
set -x will show you if the test returns true or false. Does it return false even though the file exists and have a size > 0, or what is the problem? You don't actually say what it is that doesn't work. –  Daniel Andersson Apr 13 '12 at 14:09
    
Sorry, after checking into the script I was trying to source, I believe that my shell isn't supported. I've added another edit showing what I found @DanielAndersson –  Robert Horn Apr 13 '12 at 14:39
add comment

1 Answer 1

up vote 2 down vote accepted

Answering my own question haha

Just switching the first line

#!/bin/sh

to

#!/bin/bash

in my script fixes the problem I was having. I figured out that the script that was trying to be sourced doesn't support sh.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.