bash Syntax error: "(" unexpected bash Syntax error: "(" unexpected bash bash

bash Syntax error: "(" unexpected


You're using the wrong syntax to declare functions. Use this instead:

MoveToTarget() {    # Function}

Or this:

function MoveToTarget {    # function}

But not both.

Also, I see that later on you use commas to separate arguments (MoveToTarget $SourcePath, $DestPath). That is also a problem. bash uses spaces to separate arguments, not commas. Remove the comma and you should be golden.


I'm also new to defining functions in bash scripts. I'm using a bash of version 4.3.11(1):-release (x86_64-pc-linux-gnu) on Ubuntu 14.04.

I don't know why but the definition that starts with the keyword function never works for me.

A definition like the following

function check_and_start {  echo Hello}

produces the error message:

Syntax error: "}" unexpected

If I put the { to a new line like:

function my_function{    echo Hello.}

It prints a Hello. when I run the script, even if I don't call this function at all, which is also what we want.

I don't know why this wouldn't work because I also looked at many tutorials and they all put the open curly brace at the end of the first line. Maybe it's the version of bash that we use?? Anyway, just put it here for your information.

I have to use the C-style function definition:

check_and_start() {  echo $1}check_and_start World!check_and_start Hello,\ World!

and it works as expected.


If you encounter "Syntax error: "(" unexpected"

Then use "bash" instead of using "sh"

For example:

$ bash install.sh