Badly placed ()’s error with the following shell script

It is a small error.

arr= (one two three)

should’ve been

arr=(one two three)

Also you can’t use \n in echo. Use printf if you want to use \n.

And fixing the rest of the errors, the code looks like this.

# array declaration
arr=(one two three)  

# for loop
for (( i=0;i<3;i++ ))
do
    printf "\n $((i+1)) : ${arr[i]}"
done
echo ""

Leave a Comment