Skip to content
Latchkey

bash "syntax error near unexpected token `('" in CI

The shell hit a ( where its grammar did not expect one. The usual cause in CI is a bash-only construct (an array assignment or a function name() definition) being run under /bin/sh, which on Debian and Ubuntu is dash, not bash.

What this error means

The step fails with "syntax error near unexpected token ('" pointing at an array literal like arr=(a b c)` or a function definition, even though the same script runs on your machine.

sh
deploy.sh: 3: Syntax error: "(" unexpected (expecting "}")

Common causes

A bash script executed by dash

The shebang is #!/bin/sh, or CI runs sh script.sh, and /bin/sh is dash. Bash arrays and arr=(...) are not POSIX, so dash rejects the parenthesis.

A stray or unescaped parenthesis

An unquoted ( in a case pattern, a filename, or an echo argument is read as a subshell where the grammar does not allow one.

How to fix it

Run the script with bash explicitly

  1. Set the shebang to #!/usr/bin/env bash if the script uses bash features.
  2. In CI, invoke it as bash script.sh, not sh script.sh.
  3. For GitHub Actions, set shell: bash so steps do not fall back to sh -e.
deploy.sh
#!/usr/bin/env bash
files=(a.txt b.txt c.txt)

Or write POSIX-only syntax

If the script must run under /bin/sh, avoid arrays and use a POSIX function definition: name() { ... } without the function keyword.

sh
# POSIX-safe: no arrays, no "function" keyword
greet() {
  echo "hi $1"
}

How to prevent it

  • Match the shebang and the invoking command to the features you use.
  • Run shellcheck with the right # shellcheck shell= directive.
  • Remember /bin/sh is dash on Debian/Ubuntu runners, not bash.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →