问题
I'm writing a daemon script for Linux Debian, and I'd need to be able to access the $NVM_BIN
shell environment variable, or somehow reference the path to the current "default" Node version as set in nvm.
Several of these daemon scripts will be running on the system.
Since all these scripts can share the same Node version, I'd like to reference some variable that gets automatically updated when I install a new version of Node and define it as "default", without having to manually change the Node JS reference in each script.
Is this possible?
Thanks!
回答1:
I've finally found a way to do it.
The first line of the shell script must be:
#!/bin/bash
(part of the problems I had was related to the fact that my first line was #!/bin/sh
instead)
Then, to access nvm variables or commands you must first source them with:
source <your_path>/nvm/nvm.sh
(where <your_path>
needs to be replaced with the path to your nvm folder).
Now you can get the path to the node folder in two ways.
1. Through a standard nvm variable
$NVM_BIN
2. Directly "asking" to nvm
NVM_BIN=<your_path>/`nvm version`/bin/
Nice.
来源:https://stackoverflow.com/questions/32501150/nvm-reference-default-node-version-path-in-shell-script