Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I got 'syntax error: "(" unexpected' (expecting "done") [duplicate]

Tags:

bash

shell

I have a very simple shell script which I'm using to loop through directories, and call another shell script. I wrote it on my local machine (OS X running Bash 3.2) and am using it on a remote server running Bash 4.2.

On the server, when I type which bash, I get /bin/bash, so I added the line on top. I still get this error, pointing to the line that begins arrIN=...

8: run_all_verification.sh: Syntax error: "(" unexpected (expecting "done")

The shell script:

#!/usr/bin/bash

# Base name for all experiments
BASE_EXP_ID=$1;

for i in ${BASE_EXP_ID}*
do
        # Split file name by "__"
        arrIN=(${i//__/ });
        EXP_ID=${arrIN[0]}
        NUM_FEATURES=${arrIN[1]}
        echo "${EXP_ID} ${NUM_FEATURES}"

        sh run_verification.sh ${EXP_ID} ${NUM_FEATURES}

done
like image 770
Adam_G Avatar asked Mar 26 '15 19:03

Adam_G


People also ask

What is Syntax error unexpected end of file?

Unexpected End of File errors can occur when a file doesn't have the proper closing tags. Sometimes this error can present itself as the white screen of death, or a 500 error.

How fix Unexpected end of file in Linux?

An Unexpected end of file error in a Bash script usually occurs when you there is a mismatched structure somewhere in the script. If you forget to close your quotes, or you forget to terminate an if statement, while loop, etc, then you will run into the error when you try to execute your Bash script.

What Is syntax error near unexpected token?

Why the Bash unexpected token syntax error occurs? As the error suggests this is a Bash syntax error, in other words it reports bad syntax somewhere in your script or command. There are many things that can go wrong in a Bash script and cause this error.

How do you end a Bash script?

There are many methods to quit the bash script, i.e., quit while writing a bash script, while execution, or at run time. One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.


1 Answers

Your error message is from Dash, probably because you ran sh filename.

To run a script with Bash, use bash filename (or ./filename).

like image 174
that other guy Avatar answered Sep 21 '22 10:09

that other guy