指定Yarn用于运行脚本的shell [英] Specify which shell Yarn uses for running scripts
问题描述
我的 package.json
中有一个脚本,如下所示:
My package.json
has a script in it like this:
"buildTslint":"node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/} *.ts",
请注意 {,helpers/} *.ts
部分,该部分称为括号扩展,并且只能在 bash
中使用,而不能在 sh
中使用.
Note the {,helpers/}*.ts
part, this is called Brace Expansion and is only possible in bash
, not sh
.
运行 yarn buildTslint
时,我得到以下输出:
When running yarn buildTslint
I get the following output:
# yarn buildTslint
yarn buildTslint v0.22.0
$ node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts
error TS6053: File 'node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts' not found.
error Command failed with exit code 2.
似乎Yarn使用 sh
执行这些脚本,但是我想为此使用 bash
,以便能够使用括号扩展.
It seems that Yarn uses sh
to execute these scripts, but I'd like to use bash
for this, to be able to use brace expansion.
推荐答案
它可以使用 system
函数启动命令,另请参见 man 3 system
.
It may launch the command using system
function see also man 3 system
.
要查看使用哪个系统调用:
To see which system call is used :
strace yarn ...
system
使用 fork
+ exec
+ wait
,而exec系列函数使用shell /bin/sh
system
uses fork
+exec
+wait
and the exec family functions uses shell /bin/sh
要使用bash,可以将命令更改为 bash -c'command ..'
to use bash the command can be changed to bash -c 'command ..'
这篇关于指定Yarn用于运行脚本的shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!