Q:

Shell script - Giving error while iterating through array

I have been trying to check for an If Condition on one name value in the array defined. I am experiencing this error:
main.sh: line 9: [10.247.78.207: command not found
main.sh: line 9: [10.247.78.207: command not found

Here is my code:
#!/bin/bash

declare -a names=${names:-(10.247.78.207 10.247.78.206)}

for (( i = 0 ; i < ${#names[@]} ; i++ )) 

do

if ["${names[0]}" == "10.247.78.207"]
then 
  echo "hello"
fi
done

A:

Change ["${names[0]}" == "10.247.78.207"] to [ "${names[0]}" == "10.247.78.207" ]. That is space after [ and before ]. Hope this solves your problem.

