【问题标题】:Bash script in Github Actions "[[: not found"Github Actions 中的 Bash 脚本“[[: not found”
【发布时间】:2020-10-23 22:24:35
【问题描述】:

我在 stackoverflow 上看到了几篇关于 bash 脚本中的错误导致错误的帖子:

[[: not found

我已经尝试了一切来解决这个问题,但没有任何效果。

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1 
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: bash ./run test_ts_node
      shell: bash

我找到了shell yml 选项,但似乎没有帮助。

我的 shebang 是 #!/bin/bash。

【问题讨论】:

  • 您的问题似乎缺少很多信息。究竟是什么导致了错误?错误消息中有行号吗?你能出示被指控的./run 脚本吗?
  • 我会用[替换它,它与其他shell兼容,[和[[可以做的CLI工具没有什么不能做的。
  • 可能run 命令使用了错误的shell,sh,而不是bash。

标签: bash github github-actions


【解决方案1】:

这是dash(Ubuntu 上的默认/bin/sh)在您尝试使用[[(一种bashism)时给出的消息。您的环境中有一些东西正在显式或隐式调用 sh 并期望它是 bash。

在我的系统上,dash 打印脚本的名称(或 sh,如果它是 sh -c 调用),因此查看该输出并尝试确定问题的原因可能会有所帮助。您可能还想尝试使用-x 运行您的shell 脚本,看看您是否可以找出它调用的哪个命令导致了问题。日志应向您显示导致问题的步骤,因此如果是 npm ci,那么它将在 GitHub Actions 中显示为单独的步骤,您将能够更明确地确定原因。

另请注意,Git 调用 /bin/sh,而不是 /bin/bash,因此,如果您使用调用 shell 的 Git 命令编写任何脚本,则需要避免在该脚本中编写 bashism。

您的问题出在哪里并不明显,因此如果没有更多信息,我们真的无法确定您的问题出在哪里。

【讨论】:

    猜你喜欢
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 2019-07-07
    • 2023-02-14
    • 2021-06-13
    • 2019-07-13
    • 2016-05-09
    相关资源
    最近更新 更多