o..o
o..o

Reputation: 1921

Making bash script continue after exec $SHELL

I'm making a bash script that would install rbenv and ruby.

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install $rubyVersion
rbenv global $rubyVersion

But when the exec $SHELL is called the bash process is replaced by new bash process and the script stops (of course).

How can I make the script to continue?

Upvotes: 0

Views: 1781

Answers (2)

Eric Bolinger
Eric Bolinger

Reputation: 2912

It appears that you're trying to achieve multiple objectives by modifying the .bashrc file then calling exec $SHELL. Neither of those actions will modify the shell-in-which-this-script-is-running. To modify the current shell, you want to "source" the .bashrc file. Use the "dot notation" instead of calling exec $SHELL:

. ~/.bashrc

Good luck with this one!

Upvotes: 2

Imre
Imre

Reputation: 332

replace exec $SHELL lines with "$SHELL" lines or completely remove those lines

Upvotes: 0

Related Questions