Making bash script continue after exec $SHELL












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?










share|improve this question


















  • 3





    ...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point?

    – Kenster
    Nov 26 '18 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".

    – chepner
    Nov 26 '18 at 20:21











  • After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50
















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?










share|improve this question


















  • 3





    ...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point?

    – Kenster
    Nov 26 '18 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".

    – chepner
    Nov 26 '18 at 20:21











  • After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50














0












0








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?










share|improve this question














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?







bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 20:15









o..oo..o

71411734




71411734








  • 3





    ...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point?

    – Kenster
    Nov 26 '18 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".

    – chepner
    Nov 26 '18 at 20:21











  • After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50














  • 3





    ...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point?

    – Kenster
    Nov 26 '18 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".

    – chepner
    Nov 26 '18 at 20:21











  • After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50








3




3





...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point?

– Kenster
Nov 26 '18 at 20:19





...don't invoke exec $SHELL? What are you trying to accomplish by calling exec at that point?

– Kenster
Nov 26 '18 at 20:19




2




2





exec doesn't mean "run this and wait for it to finish"; it means "run this and don't come back".

– chepner
Nov 26 '18 at 20:21





exec doesn't mean "run this and wait for it to finish"; it means "run this and don't come back".

– chepner
Nov 26 '18 at 20:21













After installing rebenv it is not loaded until I call exec $SHELL

– o..o
Nov 26 '18 at 20:50





After installing rebenv it is not loaded until I call exec $SHELL

– o..o
Nov 26 '18 at 20:50












2 Answers
2






active

oldest

votes


















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!






share|improve this answer
























  • 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

    – o..o
    Nov 26 '18 at 21:13













  • And . ~/.bashrc gives the same result..

    – o..o
    Nov 26 '18 at 21:21











  • #!/bin/bash -i helped! Thanks

    – o..o
    Nov 26 '18 at 21:37



















0














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






share|improve this answer
























  • Not working. After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50











  • c.f. Eric's answer: . ~/.bashrc

    – Paul Hodges
    Nov 26 '18 at 21:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53488369%2fmaking-bash-script-continue-after-exec-shell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









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!






share|improve this answer
























  • 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

    – o..o
    Nov 26 '18 at 21:13













  • And . ~/.bashrc gives the same result..

    – o..o
    Nov 26 '18 at 21:21











  • #!/bin/bash -i helped! Thanks

    – o..o
    Nov 26 '18 at 21:37
















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!






share|improve this answer
























  • 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

    – o..o
    Nov 26 '18 at 21:13













  • And . ~/.bashrc gives the same result..

    – o..o
    Nov 26 '18 at 21:21











  • #!/bin/bash -i helped! Thanks

    – o..o
    Nov 26 '18 at 21:37














2












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!






share|improve this answer













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!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 20:56









Eric BolingerEric Bolinger

1,002711




1,002711













  • 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

    – o..o
    Nov 26 '18 at 21:13













  • And . ~/.bashrc gives the same result..

    – o..o
    Nov 26 '18 at 21:21











  • #!/bin/bash -i helped! Thanks

    – o..o
    Nov 26 '18 at 21:37



















  • 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

    – o..o
    Nov 26 '18 at 21:13













  • And . ~/.bashrc gives the same result..

    – o..o
    Nov 26 '18 at 21:21











  • #!/bin/bash -i helped! Thanks

    – o..o
    Nov 26 '18 at 21:37

















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

– o..o
Nov 26 '18 at 21:13







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

– o..o
Nov 26 '18 at 21:13















And . ~/.bashrc gives the same result..

– o..o
Nov 26 '18 at 21:21





And . ~/.bashrc gives the same result..

– o..o
Nov 26 '18 at 21:21













#!/bin/bash -i helped! Thanks

– o..o
Nov 26 '18 at 21:37





#!/bin/bash -i helped! Thanks

– o..o
Nov 26 '18 at 21:37













0














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






share|improve this answer
























  • Not working. After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50











  • c.f. Eric's answer: . ~/.bashrc

    – Paul Hodges
    Nov 26 '18 at 21:15
















0














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






share|improve this answer
























  • Not working. After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50











  • c.f. Eric's answer: . ~/.bashrc

    – Paul Hodges
    Nov 26 '18 at 21:15














0












0








0







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 20:28









ImreImre

866




866













  • Not working. After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50











  • c.f. Eric's answer: . ~/.bashrc

    – Paul Hodges
    Nov 26 '18 at 21:15



















  • Not working. After installing rebenv it is not loaded until I call exec $SHELL

    – o..o
    Nov 26 '18 at 20:50











  • c.f. Eric's answer: . ~/.bashrc

    – Paul Hodges
    Nov 26 '18 at 21:15

















Not working. After installing rebenv it is not loaded until I call exec $SHELL

– o..o
Nov 26 '18 at 20:50





Not working. After installing rebenv it is not loaded until I call exec $SHELL

– o..o
Nov 26 '18 at 20:50













c.f. Eric's answer: . ~/.bashrc

– Paul Hodges
Nov 26 '18 at 21:15





c.f. Eric's answer: . ~/.bashrc

– Paul Hodges
Nov 26 '18 at 21:15


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53488369%2fmaking-bash-script-continue-after-exec-shell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks