syntax error near unexpected token `(' means bash met a bracket where it did not expect one, here inside an unquoted echo text. Put the text in double quotes and the script runs.

The second line of the message shows the exact line bash could not parse. Quote the words that contain ( or ), then check the file with bash -n before running it again.

The error

cat setup.sh
#!/bin/bash
echo Installing tools (step 1 of 2)
echo Done
bash setup.sh
setup.sh: line 2: syntax error near unexpected token `('
setup.sh: line 2: `echo Installing tools (step 1 of 2)'
exit code: 2

Why it happens

In bash a bare ( is not plain text the way it is in a sentence. Written unquoted in the middle of a command, as in echo Installing tools (step 1 of 2), it was refused: bash reported a syntax error, named the token it stopped at and quoted the whole line back with its number. The habit that leads here is writing an echo line the way you would write a sentence, brackets and all.

Note what did not happen: the script printed nothing at all, not even Done from line 3, and the exit code was 2. The line after the broken one did not run either, so a setup script with this mistake stops at that point and leaves its later steps undone.

The fix

cat setup.sh
#!/bin/bash
echo "Installing tools (step 1 of 2)"
echo Done
bash -n setup.sh
exit code: 0
bash setup.sh
Installing tools (step 1 of 2)
Done
exit code: 0

Inside double quotes the brackets are just characters, and both lines ran. bash -n reads the file and checks the syntax without running anything; it returned 0 for the fixed file, and printed nothing, so it is a cheap test before you run a setup script that installs things. Run on a copy of the broken file, it printed the same two lines (line 2: syntax error near unexpected token `(') with exit code 2, without running anything.

How it was reproduced

The capture was made in an ubuntu:24.04 container (Ubuntu 24.04.5 LTS, GNU bash 5.2.21, Docker Engine 29.9.2) standing in for Ubuntu in WSL. A three-line setup.sh was written with printf, shown with cat and run with bash setup.sh, which failed with exit code 2. The file was then rewritten with the text in double quotes, checked with bash -n setup.sh (exit code 0) and run again (both lines printed, exit code 0).

Frequently asked

How do I fix syntax error near unexpected token ( in bash?
Put the text that contains the bracket in double quotes. In the test echo "Installing tools (step 1 of 2)" printed the text and the script returned exit code 0.
Does bash run the rest of the script after a syntax error?
Not in this test. The script failed on line 2 and printed nothing, not even the echo on line 3, with exit code 2.
How do I check a bash script for syntax errors without running it?
Run bash -n script.sh. It returned exit code 0 for the fixed script and ran none of its commands.

More decoded errors in the Fixes category. If your script fails with "cannot execute: required file not found" instead, see the CRLF line endings post.