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?
bash
add a comment |
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
3
...don't invokeexec $SHELL
? What are you trying to accomplish by callingexec
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 callexec $SHELL
– o..o
Nov 26 '18 at 20:50
add a comment |
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
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
bash
asked Nov 26 '18 at 20:15
o..oo..o
71411734
71411734
3
...don't invokeexec $SHELL
? What are you trying to accomplish by callingexec
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 callexec $SHELL
– o..o
Nov 26 '18 at 20:50
add a comment |
3
...don't invokeexec $SHELL
? What are you trying to accomplish by callingexec
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 callexec $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
add a comment |
2 Answers
2
active
oldest
votes
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!
Thanks! Well, I have triedsource ~/.bashrc
, but it is not working when I call it in the script. The script ends becauserbenv
is not found. But when it ends and I call it manually, after that therbenv
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
add a comment |
replace exec $SHELL lines with "$SHELL" lines or completely remove those lines
Not working. After installing rebenv it is not loaded until I callexec $SHELL
– o..o
Nov 26 '18 at 20:50
c.f. Eric's answer:. ~/.bashrc
– Paul Hodges
Nov 26 '18 at 21:15
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
Thanks! Well, I have triedsource ~/.bashrc
, but it is not working when I call it in the script. The script ends becauserbenv
is not found. But when it ends and I call it manually, after that therbenv
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
add a comment |
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!
Thanks! Well, I have triedsource ~/.bashrc
, but it is not working when I call it in the script. The script ends becauserbenv
is not found. But when it ends and I call it manually, after that therbenv
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
add a comment |
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!
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!
answered Nov 26 '18 at 20:56
Eric BolingerEric Bolinger
1,002711
1,002711
Thanks! Well, I have triedsource ~/.bashrc
, but it is not working when I call it in the script. The script ends becauserbenv
is not found. But when it ends and I call it manually, after that therbenv
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
add a comment |
Thanks! Well, I have triedsource ~/.bashrc
, but it is not working when I call it in the script. The script ends becauserbenv
is not found. But when it ends and I call it manually, after that therbenv
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
add a comment |
replace exec $SHELL lines with "$SHELL" lines or completely remove those lines
Not working. After installing rebenv it is not loaded until I callexec $SHELL
– o..o
Nov 26 '18 at 20:50
c.f. Eric's answer:. ~/.bashrc
– Paul Hodges
Nov 26 '18 at 21:15
add a comment |
replace exec $SHELL lines with "$SHELL" lines or completely remove those lines
Not working. After installing rebenv it is not loaded until I callexec $SHELL
– o..o
Nov 26 '18 at 20:50
c.f. Eric's answer:. ~/.bashrc
– Paul Hodges
Nov 26 '18 at 21:15
add a comment |
replace exec $SHELL lines with "$SHELL" lines or completely remove those lines
replace exec $SHELL lines with "$SHELL" lines or completely remove those lines
answered Nov 26 '18 at 20:28
ImreImre
866
866
Not working. After installing rebenv it is not loaded until I callexec $SHELL
– o..o
Nov 26 '18 at 20:50
c.f. Eric's answer:. ~/.bashrc
– Paul Hodges
Nov 26 '18 at 21:15
add a comment |
Not working. After installing rebenv it is not loaded until I callexec $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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
3
...don't invoke
exec $SHELL
? What are you trying to accomplish by callingexec
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