Bash reload to find an executable after installing from a script











up vote
-1
down vote

favorite












I'm trying to write a little shell script to install nvm and then to install a node version specified in the .nvmrc file. The installation of nvm seems to be succesful, but I can not call nvm install, because $(command -v nvm) has no output. Also in the terminal, I get the message from the nvm install.sh script:




=> Close and reopen your terminal to start using nvm or run the following to use it now:




#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
fi

source ~/.bash_profile
source ~/.bashrc

if [ -x "$(command -v nvm)" ]; then
nvm install
exit 0
fi
exit 1


How to use the command nvm in the bash script?










share|improve this question
























  • Did you try hash -r nvm? Though probably you also need to reload your .bashrc or .bash_profile if it made edits to that. ("Do the following" probably explains in more detail what exactly you need, but you don't reveal where this quote is from so I can't check.)
    – tripleee
    Nov 8 at 11:42












  • By the way, you should probably simply exit to return the result from nvm rather than blindly assume it finished successfully.
    – tripleee
    Nov 8 at 11:43












  • "You should probably simply exit to return the result from nvm rather than blindly assume it finished successfully" Yes, but for now I only need to call nvm install. You can assume nvm is installed successfully.
    – BuZZ-dEE
    Nov 8 at 11:52












  • @tripleee I've added source ~/.bash_profile and source ~/.bashrc to the script file. Could you clarify what hash -r nvm does? I get no output for hash -r nvm in a bash, where I can call nvm successfully.
    – BuZZ-dEE
    Nov 8 at 12:01










  • @tripleee thx now I know what hash -r nvm does. It solved my problem. :)
    – BuZZ-dEE
    Nov 8 at 12:09















up vote
-1
down vote

favorite












I'm trying to write a little shell script to install nvm and then to install a node version specified in the .nvmrc file. The installation of nvm seems to be succesful, but I can not call nvm install, because $(command -v nvm) has no output. Also in the terminal, I get the message from the nvm install.sh script:




=> Close and reopen your terminal to start using nvm or run the following to use it now:




#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
fi

source ~/.bash_profile
source ~/.bashrc

if [ -x "$(command -v nvm)" ]; then
nvm install
exit 0
fi
exit 1


How to use the command nvm in the bash script?










share|improve this question
























  • Did you try hash -r nvm? Though probably you also need to reload your .bashrc or .bash_profile if it made edits to that. ("Do the following" probably explains in more detail what exactly you need, but you don't reveal where this quote is from so I can't check.)
    – tripleee
    Nov 8 at 11:42












  • By the way, you should probably simply exit to return the result from nvm rather than blindly assume it finished successfully.
    – tripleee
    Nov 8 at 11:43












  • "You should probably simply exit to return the result from nvm rather than blindly assume it finished successfully" Yes, but for now I only need to call nvm install. You can assume nvm is installed successfully.
    – BuZZ-dEE
    Nov 8 at 11:52












  • @tripleee I've added source ~/.bash_profile and source ~/.bashrc to the script file. Could you clarify what hash -r nvm does? I get no output for hash -r nvm in a bash, where I can call nvm successfully.
    – BuZZ-dEE
    Nov 8 at 12:01










  • @tripleee thx now I know what hash -r nvm does. It solved my problem. :)
    – BuZZ-dEE
    Nov 8 at 12:09













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm trying to write a little shell script to install nvm and then to install a node version specified in the .nvmrc file. The installation of nvm seems to be succesful, but I can not call nvm install, because $(command -v nvm) has no output. Also in the terminal, I get the message from the nvm install.sh script:




=> Close and reopen your terminal to start using nvm or run the following to use it now:




#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
fi

source ~/.bash_profile
source ~/.bashrc

if [ -x "$(command -v nvm)" ]; then
nvm install
exit 0
fi
exit 1


How to use the command nvm in the bash script?










share|improve this question















I'm trying to write a little shell script to install nvm and then to install a node version specified in the .nvmrc file. The installation of nvm seems to be succesful, but I can not call nvm install, because $(command -v nvm) has no output. Also in the terminal, I get the message from the nvm install.sh script:




=> Close and reopen your terminal to start using nvm or run the following to use it now:




#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
fi

source ~/.bash_profile
source ~/.bashrc

if [ -x "$(command -v nvm)" ]; then
nvm install
exit 0
fi
exit 1


How to use the command nvm in the bash script?







node.js bash shell nvm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 11:54

























asked Nov 8 at 11:29









BuZZ-dEE

1,26422651




1,26422651












  • Did you try hash -r nvm? Though probably you also need to reload your .bashrc or .bash_profile if it made edits to that. ("Do the following" probably explains in more detail what exactly you need, but you don't reveal where this quote is from so I can't check.)
    – tripleee
    Nov 8 at 11:42












  • By the way, you should probably simply exit to return the result from nvm rather than blindly assume it finished successfully.
    – tripleee
    Nov 8 at 11:43












  • "You should probably simply exit to return the result from nvm rather than blindly assume it finished successfully" Yes, but for now I only need to call nvm install. You can assume nvm is installed successfully.
    – BuZZ-dEE
    Nov 8 at 11:52












  • @tripleee I've added source ~/.bash_profile and source ~/.bashrc to the script file. Could you clarify what hash -r nvm does? I get no output for hash -r nvm in a bash, where I can call nvm successfully.
    – BuZZ-dEE
    Nov 8 at 12:01










  • @tripleee thx now I know what hash -r nvm does. It solved my problem. :)
    – BuZZ-dEE
    Nov 8 at 12:09


















  • Did you try hash -r nvm? Though probably you also need to reload your .bashrc or .bash_profile if it made edits to that. ("Do the following" probably explains in more detail what exactly you need, but you don't reveal where this quote is from so I can't check.)
    – tripleee
    Nov 8 at 11:42












  • By the way, you should probably simply exit to return the result from nvm rather than blindly assume it finished successfully.
    – tripleee
    Nov 8 at 11:43












  • "You should probably simply exit to return the result from nvm rather than blindly assume it finished successfully" Yes, but for now I only need to call nvm install. You can assume nvm is installed successfully.
    – BuZZ-dEE
    Nov 8 at 11:52












  • @tripleee I've added source ~/.bash_profile and source ~/.bashrc to the script file. Could you clarify what hash -r nvm does? I get no output for hash -r nvm in a bash, where I can call nvm successfully.
    – BuZZ-dEE
    Nov 8 at 12:01










  • @tripleee thx now I know what hash -r nvm does. It solved my problem. :)
    – BuZZ-dEE
    Nov 8 at 12:09
















Did you try hash -r nvm? Though probably you also need to reload your .bashrc or .bash_profile if it made edits to that. ("Do the following" probably explains in more detail what exactly you need, but you don't reveal where this quote is from so I can't check.)
– tripleee
Nov 8 at 11:42






Did you try hash -r nvm? Though probably you also need to reload your .bashrc or .bash_profile if it made edits to that. ("Do the following" probably explains in more detail what exactly you need, but you don't reveal where this quote is from so I can't check.)
– tripleee
Nov 8 at 11:42














By the way, you should probably simply exit to return the result from nvm rather than blindly assume it finished successfully.
– tripleee
Nov 8 at 11:43






By the way, you should probably simply exit to return the result from nvm rather than blindly assume it finished successfully.
– tripleee
Nov 8 at 11:43














"You should probably simply exit to return the result from nvm rather than blindly assume it finished successfully" Yes, but for now I only need to call nvm install. You can assume nvm is installed successfully.
– BuZZ-dEE
Nov 8 at 11:52






"You should probably simply exit to return the result from nvm rather than blindly assume it finished successfully" Yes, but for now I only need to call nvm install. You can assume nvm is installed successfully.
– BuZZ-dEE
Nov 8 at 11:52














@tripleee I've added source ~/.bash_profile and source ~/.bashrc to the script file. Could you clarify what hash -r nvm does? I get no output for hash -r nvm in a bash, where I can call nvm successfully.
– BuZZ-dEE
Nov 8 at 12:01




@tripleee I've added source ~/.bash_profile and source ~/.bashrc to the script file. Could you clarify what hash -r nvm does? I get no output for hash -r nvm in a bash, where I can call nvm successfully.
– BuZZ-dEE
Nov 8 at 12:01












@tripleee thx now I know what hash -r nvm does. It solved my problem. :)
– BuZZ-dEE
Nov 8 at 12:09




@tripleee thx now I know what hash -r nvm does. It solved my problem. :)
– BuZZ-dEE
Nov 8 at 12:09












1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you want to simply modify the environment with the command given by the script without reloading the whole profile use :



eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"


grep will remove the comments starting with => and potentially a leading hidden character.
eval will execute the commands in the current shell.



then do not use -x since command -v nvm returns nvm and not the full path.
if [ -n "$(command -v nvm)" ]; then
nvm install
exit $?
fi



And following triplee advice use a bare exit to keep the return code.



Script becomes:



#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"
fi

if [ -n "$(command -v nvm)" ]; then
nvm install
exit
fi
exit 1





share|improve this answer























  • Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
    – BuZZ-dEE
    Nov 8 at 12:53










  • That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
    – Eric Le Blouc'h
    Nov 9 at 15:19











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',
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%2f53206859%2fbash-reload-to-find-an-executable-after-installing-from-a-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













If you want to simply modify the environment with the command given by the script without reloading the whole profile use :



eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"


grep will remove the comments starting with => and potentially a leading hidden character.
eval will execute the commands in the current shell.



then do not use -x since command -v nvm returns nvm and not the full path.
if [ -n "$(command -v nvm)" ]; then
nvm install
exit $?
fi



And following triplee advice use a bare exit to keep the return code.



Script becomes:



#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"
fi

if [ -n "$(command -v nvm)" ]; then
nvm install
exit
fi
exit 1





share|improve this answer























  • Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
    – BuZZ-dEE
    Nov 8 at 12:53










  • That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
    – Eric Le Blouc'h
    Nov 9 at 15:19















up vote
0
down vote













If you want to simply modify the environment with the command given by the script without reloading the whole profile use :



eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"


grep will remove the comments starting with => and potentially a leading hidden character.
eval will execute the commands in the current shell.



then do not use -x since command -v nvm returns nvm and not the full path.
if [ -n "$(command -v nvm)" ]; then
nvm install
exit $?
fi



And following triplee advice use a bare exit to keep the return code.



Script becomes:



#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"
fi

if [ -n "$(command -v nvm)" ]; then
nvm install
exit
fi
exit 1





share|improve this answer























  • Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
    – BuZZ-dEE
    Nov 8 at 12:53










  • That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
    – Eric Le Blouc'h
    Nov 9 at 15:19













up vote
0
down vote










up vote
0
down vote









If you want to simply modify the environment with the command given by the script without reloading the whole profile use :



eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"


grep will remove the comments starting with => and potentially a leading hidden character.
eval will execute the commands in the current shell.



then do not use -x since command -v nvm returns nvm and not the full path.
if [ -n "$(command -v nvm)" ]; then
nvm install
exit $?
fi



And following triplee advice use a bare exit to keep the return code.



Script becomes:



#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"
fi

if [ -n "$(command -v nvm)" ]; then
nvm install
exit
fi
exit 1





share|improve this answer














If you want to simply modify the environment with the command given by the script without reloading the whole profile use :



eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"


grep will remove the comments starting with => and potentially a leading hidden character.
eval will execute the commands in the current shell.



then do not use -x since command -v nvm returns nvm and not the full path.
if [ -n "$(command -v nvm)" ]; then
nvm install
exit $?
fi



And following triplee advice use a bare exit to keep the return code.



Script becomes:



#!/bin/bash

if ! [ -x "$(command -v nvm)" ]; then
echo 'Installing Node version manager (http://nvm.sh).' >&2
eval "$(curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | grep -E -v "^.?=>")"
fi

if [ -n "$(command -v nvm)" ]; then
nvm install
exit
fi
exit 1






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 15:20

























answered Nov 8 at 12:43









Eric Le Blouc'h

116




116












  • Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
    – BuZZ-dEE
    Nov 8 at 12:53










  • That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
    – Eric Le Blouc'h
    Nov 9 at 15:19


















  • Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
    – BuZZ-dEE
    Nov 8 at 12:53










  • That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
    – Eric Le Blouc'h
    Nov 9 at 15:19
















Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
– BuZZ-dEE
Nov 8 at 12:53




Thx for your annswer. if ! [ -x "$(command -v nvm)" ]; does not work. Even if nvm is already installed, the if block is executed.
– BuZZ-dEE
Nov 8 at 12:53












That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
– Eric Le Blouc'h
Nov 9 at 15:19




That is what I said, -x check the path when command -v nvm returns nvm. So I changed the test to -n that checks if the string is not empty and then it works well.
– Eric Le Blouc'h
Nov 9 at 15:19


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206859%2fbash-reload-to-find-an-executable-after-installing-from-a-script%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

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff