Skip to content
John Gardner edited this page Dec 22, 2021 · 5 revisions

( is invalid here. Did you forget to escape it?

Problematic code:

echo (foo) bar

Correct code:

Depends on your intention:

echo "(foo) bar"  # Literal parentheses
echo "$(foo) bar" # Command expansion
echo "foo bar"    # Tried to use parentheses for grouping or function invocation

Rationale:

ShellCheck expected an ordinary shell word but found an opening parenthesis instead.

Determine what you intended the parenthesis to do and rewrite accordingly. Common issues include:

  • Wanting them to be literal, as in echo (FAIL) Some tests failed. In this case, it requires quoting.
  • Wanting command expansion, as in echo Today is (date). Add the missing $: echo "Today is $(date)"
  • Adding parentheses because other languages need them in that context, such as foo (bar, 42) to call a function. This should be foo bar 42. Also, shells do not support tuples or passing arrays as single parameters.

Exceptions:

Bash allows some parentheses as part of assignment-like tokens to certain commands, including export and eval. This is a workaround in Bash to allow commands that normally would not be valid:

eval foo=(bar)       # Valid command
echo foo=(bar)       # Invalid syntax
f=foo; eval $f=(bar) # Also invalid

In these cases, please quote the command, such as eval "foo=(bar)". This does not change the behavior, but stops relying on Bash-specific parsing quirks.

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally