Software⏱️ 3 min read📅 2026-06-19

How to Fix: Bash error while running script

Bash script error fix for CentOS 6.5 dedicated server.

Quick Answer: The issue is due to the shebang line not being correctly formatted, try changing `#!/bin/bash` to `#!/bin/sh` and make sure the file has execute permissions by running `chmod +x test.sh`

The error 'syntax error near unexpected token `done' and 'Permission denied' occurs when trying to run a Bash script on a CentOS 6.5 dedicated server. This issue affects users who have installed Java 7 using yum and are running the script in the root directory or any other directory.

This error can be frustrating as it prevents the user from executing their intended script, causing downtime and lost productivity. However, by following these steps, you should be able to resolve the issue and get your script running smoothly.

🛑 Root Causes of the Error

  • The primary cause of this error is that the Bash shell in CentOS 6.5 does not support the `done` keyword in a while loop. The `done` keyword is typically used in other shells like Zsh or Fish, but Bash uses `break` instead.
  • An alternative reason for this issue could be related to file permissions. If the script is not set as executable, you may get a 'Permission denied' error when trying to run it.

🚀 How to Resolve This Issue

Fixing the Syntax Error

  1. Step 1: Step 1: Open the test.sh file in a text editor and replace the `done` keyword with `break`. This will fix the syntax error.
  2. Step 2: Step 2: Save the changes to the script and make sure it is still set as executable by running the command `chmod +x test.sh` in the root directory.
  3. Step 3: Step 3: Try running the script again using either `bash test.sh` or `./test.sh`. If you get the 'Permission denied' error, proceed with method 2.

Fixing the Permission Denied Error

  1. Step 1: Step 1: Run the command `chmod +x test.sh` in the root directory to make the script executable.
  2. Step 2: Step 2: Try running the script again using either `bash test.sh` or `./test.sh`. If you still get the 'Permission denied' error, proceed with further troubleshooting.

🎯 Final Words

By following these steps, you should be able to resolve the issue and run your Bash script successfully. Remember to always check file permissions and syntax errors before trying to execute a script.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions