8

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
1
  • 2
    If you mean bash then run bash and not sh (for run_verification.sh). How are you running the posted script (which is run_all_verification.sh I'm assuming)? ./run_all_verification.sh? sh run_all_verification.sh? bash run_all_verification.sh? Commented Mar 26, 2015 at 19:53

1 Answer 1

25

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

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

Sign up to request clarification or add additional context in comments.

5 Comments

I didn't realize there's a difference. On my local machine, and on the server, I run sh run_all_verification.sh...
Just never run a bash script with sh. It will almost always fail on Debian-ish distributions where sh is dash. It can even fail on OS X where sh is bash, due to compatibility settings.
When I run ./run_all..sh I get 'Permission denied'. When I run bash run_all.sh, I get 'Cannot open run_verification.sh', which is the script that is being called internally
Disregard. I had the wrong file name
You can give yourself permission to execute your file with chmod +x yourfile. Remember that sh run_verification.sh has the same bash vs sh issue that you originally saw, and that it will look for run_verification.sh in the current working directory and not necessarily the directory where run_all.sh is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.