nvm:引用“默认"Shell脚本中的节点版本路径 [英] nvm: reference "default" node version path in Shell script

查看:83
本文介绍了nvm:引用“默认"Shell脚本中的节点版本路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Linux Debian编写一个守护程序脚本,并且需要能够访问 $ NVM_BIN shell环境变量,或者以某种方式引用当前默认"节点的路径. nvm 中设置的版本.

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.

由于所有这些脚本可以共享相同的Node版本,因此我想引用一些在安装新版本的Node并将其定义为默认"时会自动更新的变量,而无需手动更改Node JS.每个脚本中的参考.

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.

这可能吗?

谢谢!

推荐答案

我终于找到了一种方法.

I've finally found a way to do it.

shell脚本的第一行必须为:

The first line of the shell script must be:

#!/bin/bash

(我遇到的部分问题与我的第一行是#!/bin/sh 相反)

(part of the problems I had was related to the fact that my first line was #!/bin/sh instead)

然后,要访问nvm变量或命令,您必须首先使用以下命令获取它们:

Then, to access nvm variables or commands you must first source them with:

source <your_path>/nvm/nvm.sh

(其中< your_path> 需要替换为您的nvm文件夹的路径).

(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.通过标准的nvm变量

$NVM_BIN

2.直接询问"到nvm

NVM_BIN=<your_path>/`nvm version`/bin/

很好.

这篇关于nvm:引用“默认"Shell脚本中的节点版本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆