As it is going to be used as part of some automation and not just at the command line I was wondering if it could be improved at all.
Improve would mean any of:
- handle sad cases better
- handle error better
- report errors better
- better able to work on multiple linux OS including OSX
Improve would NOT mean:
- shorter code
- short variable names
- Linux shell version specific tricks or shortcuts
- allowing for rvm not being present (checked elsewhere)
function make_sure_rvm_rubies_installed() {
rvm list > $TMP/local_ruby_versions.txt
local_ruby_versions=(1.8.7 1.9.3)
for version in "${local_ruby_versions[@]}"
do
cat $TMP/local_ruby_versions.txt | grep -q $version
version_search_result=$?
if [ $version_search_result = 0 ]
then
echo "Required RVM Ruby version $version confirmed as present on this machine"
else
echo "*** EXITING SMOKE TEST *** - not all required ruby versions are present in RVM"
echo "Please install RVM ruby version: $version and then re-run this program"
exit
fi
done
if [ $? = 0 ]
then echo "All required Ruby Versions confirmed as present locally"
fi
}
make_sure_rvm_rubies_installed