bashshell

bash: Why am I getting syntax error near unexpected token `}'?


I have a very simple script number_guess.sh which is running inside a docker container and using vs-code with utf-8 character encoding in settings without automatically changing encoding based on file.

#!/bin/bash

echo "hello!";

HELLO () {
  # function budy
}

This keeps generating the following error:

./number_guess.sh: line 7: syntax error near unexpected token `}'
./number_guess.sh: line 7: `}'

I have tried adding and removing spaces but to no avail. I have also tried to explicitly save file with encoding utf-8 using the editor but also to no avail.

I don't know what is causing the issue and I feel lost.


Solution

  • Your function body cannot be empty:

    HELLO() {
      echo "hello!"
    }
    

    This will work