You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用**/*路径匹配时npm脚本执行失败,生成空SHA256SUM文件

问题原因

npm 默认使用 POSIX 标准的 sh 执行脚本命令,而非你终端默认的 bash。sh 不支持 ** 递归通配符以及 {bin,lib} 这种大括号扩展语法,导致命令匹配不到任何文件,最终生成空的 SHA256SUM 文件。

解决方案

方案一:指定用 bash 执行脚本

修改 package.json 中的 scripts,明确调用 bash 执行命令,保留原语法:

{
  "scripts": {
    "checksum": "bash -c 'shasum --algorithm 256 ./{bin,lib}/**/* > SHA256SUM'"
  }
}

方案二:用 find 命令兼容所有 shell

如果需要命令在任意 shell 环境下都能运行,改用 find 遍历文件:

{
  "scripts": {
    "checksum": "find ./bin ./lib -type f -exec shasum --algorithm 256 {} + > SHA256SUM"
  }
}

find 会递归遍历 bin 和 lib 下的所有普通文件,再批量执行哈希计算并写入结果文件。

内容的提问来源于stack exchange,提问作者sunknudsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 22:50:21