I am writing a bash script to attempt to automate initial setup on Ubuntu, and I have run into an issue I do not understand. If I run the following code:
sudo apt-get -y update && sudo apt-get -y upgrade
sudo apt-get -y install curl git-core build-essential openssl sqlite3 apache2-prefork-dev mysql-client
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install -v 1.9.3-p392
....
then the script finishes, but most of the commands fail, as rbenv
is undefined (tested after script finishes with rbenv -v
). If I then run source ~/.bashrc
, rbenv
becomes defined.
However, if I run the exact same code but replace source ~/.bashrc
with source /home/username/.bashrc
, then rbenv
is defined and the script completes without problems. Can someone explain this discrepancy? Understanding when and why relative pathing doesn't work I suspect will be very useful in the future.
source
understood...