【问题标题】:Parenthesis in npm scriptnpm 脚本中的括号
【发布时间】:2020-06-19 18:16:01
【问题描述】:

我使用以下 shell 命令来激活我的提示。在 shell 中工作正常。

source <(curl -s https://gist.githubusercontent.com/jbnv/78ce47382faf454553ef/raw/4382bf0a2ac3742dfd777e34fbb14b16b0f3d06b/prompt.sh)

我把它放到一个 NPM 脚本中,这样我就可以在多个项目之间共享它,而不必完全输入它:

"scripts": {
    "prompt": "source <(curl -s https://gist.githubusercontent.com/jbnv/78ce47382faf454553ef/raw/4382bf0a2ac3742dfd777e34fbb14b16b0f3d06b/prompt.sh)"
},

当我npm run script 时,它会抛出sh: 1: Syntax error: "(" unexpected

我该如何解决这个问题?

【问题讨论】:

  • Npm 使用 sh 作为执行 npm 脚本的默认 shell - 而不是 bash。如here 所述,sh 不支持进程替换,即&lt;()。要么尝试; A) 将您的脚本作为字符串传递给bash -c,例如将您的 npm 脚本定义为; "prompt": "bash -c \"source &lt;(curl -s https://gist.githubusercontent.com/jbnv/78ce47382faf454553ef/raw/4382bf0a2ac3742dfd777e34fbb14b16b0f3d06b/prompt.sh)\""
  • B) 或者尝试使用npm-config 命令将script-shell 设置改为bash。您可以运行 which bash 来获取 bash 的路径,然后运行类似的东西; npm config set script-shell "/bin/bash" - 上述示例中的 /bin/bash 部分应替换为从 which bash 返回的路径
  • A 和 B 都不起作用,看起来原因是 NPM 在自己的 shell 中运行命令。因此,提示在命令后消失的 shell 中发生了变化。如果是这种情况,则没有解决方案,因为该命令永远不会按预期工作。

标签: npm npm-scripts


【解决方案1】:

所以按照图片中的说明试试这个

"prompt": "source '<(curl -s https://gist.githubusercontent.com/jbnv/78ce47382faf454553ef/raw/4382bf0a2ac3742dfd777e34fbb14b16b0f3d06b/prompt.sh)'"

【讨论】:

  • sh: 1: source: not found
猜你喜欢
  • 2015-08-17
  • 1970-01-01
  • 2012-11-05
  • 1970-01-01
  • 1970-01-01
  • 2020-08-08
  • 1970-01-01
  • 1970-01-01
  • 2013-10-17
相关资源
最近更新 更多