简体   繁体   English

为什么相同的通配符在 shell 和 npm 脚本中表现不同?

[英]Why same wildcards behave differently in shell and npm script?

I want use ./src/**/*.js to match every js file in ./src folder,no matter how deep the file path is.我想使用./src/**/*.js来匹配./src文件夹中的每个 js 文件,无论文件路径有多深。

so I run ls ./src/**/*.js in the shell and the wildcards behave as I expected, js files like ./src/path1/a.js ./src/path1/path2/b.js and both matched.所以我在 shell 中运行ls ./src/**/*.js并且通配符的行为符合我的预期,js 文件如./src/path1/a.js ./src/path1/path2/b.js和两者匹配。

And then I add npm script in package.json然后我在 package.json 中添加 npm 脚本

{
  scripts: {
    "test": "ls ./src/**/*.js"
  }
}

run npm run test .运行npm run test But now only files like ./src/pah1/a.js are matched.但现在只匹配./src/pah1/a.js类的文件。

I don't know why same wildcards behave differently.Can anyone tell me what is the right wildcards that I can use to match every js files in one folder.我不知道为什么相同的通配符表现不同。谁能告诉我什么是正确的通配符,我可以使用它来匹配一个文件夹中的每个 js 文件。

Thank you.谢谢你。

They're just different.他们只是不同。 Shells don't expand ** .外壳不会扩展** Try find ./src -name '*.js' , instead.尝试find ./src -name '*.js' ,而不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM