0

I have the following script, which works fine until the end of the script where the line to install JRuby 1.7.0.RC2 works, but then the script stops.

I added $? at the end of the script to try to get it to output the exit code from the previous line but the error code doesn't get printed.

#!/bin/bash

# Update OS
sudo apt-get -y update
sudo apt-get -y upgrade 

# Install package dependencies
sudo apt-get -y install git-core curl make g++ openjdk-6-jre-headless ant openjdk-6-jdk redis-server

# Install rbenv
cd ~
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bashrc
source ~/.bash_profile

# Install ruby-build:
cd ~
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
sudo ./install.sh

# Install JRuby 1.7.0.RC2
echo 'install_package "jruby-1.7.0.RC2" "http://jruby.org.s3.amazonaws.com/downloads/1.7.0.RC2/jruby-bin-1.7.0.RC2.tar.gz" jruby' > jruby-1.7.0-rc2
~/.rbenv/bin/rbenv install jruby-1.7.0-rc2
$?

# /\ That last line never gets run
# \/ I excluded the rest of script, as the problem seems to be right here
...

If I run the JRuby install command by hand (copy/paste it in the console) the exit code is 0, so I would expect the script to continue uninterrupted.

jefflunt
  • 300
  • 3
  • 15

1 Answers1

1

Whether the JRuby install command succeeds or fails wouldn't matter to the script, since it doesn't check the return code in order to apply any logic.

My guess is that the problem is with the previous command. First, do you get the sudo prompt for a password? Second, how does "install.sh" end? It may do an exit; since it's run in the same shell, that would cause your shell to exit. To prevent this from happening, you would want to run it in a secondary shell, usually done by using something like sh ./install.sh.

Marty Fried
  • 136
  • 4
  • No prompt for a password - my user has password-less sudo access. The `install.sh` script ends with the following line: `echo "Installed ruby-build at ${PREFIX}"` (no exit). However, your suggestion of running it a secondary shell seems like progress. – jefflunt Oct 10 '12 at 19:59
  • I could be remembering incorrectly; it may well be that it is normal for the shell to terminate when the script ends, even without an exit. It's been a while since I've done anything except simple scripts using bash. – Marty Fried Oct 10 '12 at 21:53