OS: Ubuntu 14.04
I am new to shell programming (and I don't have time to become an expert, as this is something I do not envision doing in regular basis), but I need to do some stuff in scripts to prep for Rails app deployments. I have the following script:
#!/bin/bash
cd ~
sudo ls -l
read -p $'Enter version of Ruby you want to use, ex: 2.1.7\n' rubyv
if [ "$rubyv" = '' ]; then
echo 'You did not enter a Ruby version to use, exiting...'
exit
fi
echo ' You entered '$rubyv
read -rsp $'If this not what you wanted press any key to exit, otherwise, press c to continue\n' -n1 key
if [ "$key" != 'c' ]; then
exit
fi
Then I would like to continue the script by using $rubyv to install Ruby using rvm, something like:
rvm install "$rubyv"
For a test, I tried entering a directory name that I created, and then added this to the end of the script:
cd "$rubyv"
But nothing is happening. What am I missing?
Solution:
It appears as the cd command is executing fine, but the reason I do not see it, is that when the script exists, I am returned to ~, the directory I started from. I verified that I was in the directory that I cd to, by doing an ls -l at the end of the script, and it did give me the proper listing
rvm install $rubyvin that script?pwdat the end of the script. It won't change the parent environment.echo $rubyv. What do you mean by nothing happens. For me that script works and I can see output. How do you execute it? Is it executable?chmod +x script.sh