运行npm脚本时使用哪个shell npm?

我在通过ConEmu运行鱼壳的Windows上。 鱼默认不承认“&&”运营商, 但是有这样的:

"scripts": { "test": "echo 'a' && echo 'b'" } 

并运行“npm run test”正在工作。 所以我认为它必须使用默认的“cmd”,这就是npm config ls -l | grep shell 然而, npm config ls -l | grep shell说,当我把“testing”脚本改为:

 "scripts": { "test": "echo 'a' && ls" } 

这也可以工作,而ls显然不支持“cmd”。

这到底是怎么回事? 😲

我不知道在你的情况下使用了什么shell,也不知道检查哪个shell是npm使用的首选方法,但我有一些一般的提示,这可能会有所帮助。

你可以试试

 { "scripts": { "test": "echo $0" } } 

这可以产生如下结果:

 $ npm run test > @ test /home/matmat/test > echo $0 sh 

(用于Linux上的bash)

要么

 C:\Users\qbolec\Documents\test>npm run test > @ test C:\Users\qbolec\Documents\test > echo $0 $0 

在Windows Node.js命令提示符下。

你也可以试试

  "test": "which ls" 

得到一些更多的信息。

看起来行npm run将命令发送到sh shell,通常指向默认的Bourne兼容shell。 我没有你的模拟器的经验,但我敢打赌,它是在你的环境中使用bash (因为鱼不是Bourne兼容的)。