0

i am having a bit of an issue with the below bash script that it always has the error ./check2.sh: 2: Syntax error: "(" unexpected , i have tried every which way to try and fix this i am probably missing something simple. can anyone give me some guidance

# array of dependencies
array=("convert" "ffmpeg");
for i in "${array[@]}"
do
    command -v $i >/dev/null 2>&1 || { 
        echo >&2 "$i required"; 
        exit 1; 
    }
done
0

1 Answer 1

0

You probably need to add a shebang to make sure the code executes in bash and not the default shell. At the start of the script there should be the line:

#!/bin/bash

This is because your array syntax is only supported in Bash, not in more basic shells which are often used by default for performance reasons.

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

1 Comment

Note that this is a very common problem; such questions should be closed as duplicates rather than answered, as described in the "Answer Well-Asked Questions" section of stackoverflow.com/help/how-to-answer