Reputation: 940
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
Upvotes: 0
Views: 72
Reputation: 16
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.
Upvotes: 0
Reputation: 7834
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
you need spaces around [
and ]
Upvotes: 1