Coding⏱️ 3 min read📅 2026-06-11

How to Fix: Why did ; after & return an unexpected token error in bash?

Error fixing syntax near unexpected token ; in bash command

Quick Answer: Use the semicolon (;) correctly by separating commands with && instead of ;.

The error 'bash: syntax error near unexpected token ';'' occurs when attempting to run commands in the background using the '&' symbol. This issue affects users who are unfamiliar with bash scripting or have not properly separated their commands.

This error can be frustrating for users as it prevents them from running multiple commands simultaneously, hindering productivity and workflow efficiency.

💡 Why You Are Getting This Error

  • The primary reason for this error is the misuse of the ';' symbol. In bash, ';'' should not be used to separate commands when using '&' to background a job. The correct way to do so is by separating each command with a space or by using the '&' symbol alone after the last command.
  • Another possible cause could be the presence of other special characters or syntax errors in the command line. However, in this case, the issue seems to be specifically related to the use of ';'' as a separator.

🚀 How to Resolve This Issue

Correctly separating commands with spaces

  1. Step 1: To fix this issue, replace the ';' symbol with a space between commands. For example: evince foo.pdf bar.pdf & emacs foo.tex &
  2. Step 2: Alternatively, you can remove the '&' symbol after the last command, like so: evince foo.pdf bar.pdf && emacs foo.tex

Avoiding special characters in command separators

  1. Step 1: To avoid this issue in the future, make sure to properly escape any special characters or syntax errors in your command line. For example, if you need to use a semicolon ';'' in your command, you can escape it by prefixing it with a backslash '\';'.
  2. Step 2: It's also a good practice to review and test your bash scripts before running them to ensure they work as expected.

💡 Conclusion

By following these steps, users should be able to correctly separate commands in the background using '&' and avoid the 'bash: syntax error near unexpected token ';'' error. Remember to always review your command lines for any potential errors or special characters that could cause issues.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions