0

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?

3
  • 3
    ...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point? Commented Nov 26, 2018 at 20:19
  • 2
    exec doesn't mean "run this and wait for it to finish"; it means "run this and don't come back". Commented Nov 26, 2018 at 20:21
  • After installing rebenv it is not loaded until I call exec $SHELL Commented Nov 26, 2018 at 20:50

2 Answers 2

2

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Well, I have tried source ~/.bashrc, but it is not working when I call it in the script. The script ends because rbenv is not found. But when it ends and I call it manually, after that the rbenv is found and ruby can be installed. Weird
#!/bin/bash -i helped! Thanks
0

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

2 Comments

Not working. After installing rebenv it is not loaded until I call exec $SHELL
c.f. Eric's answer: . ~/.bashrc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.