0

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
2
  • 4
    [ is a command. You need spaces around [ and ]. Commented Apr 24, 2014 at 6:09
  • Since you are using BASH, you should use [[ instead of [. See mywiki.wooledge.org/BashFAQ/031 Commented Apr 24, 2014 at 6:48

2 Answers 2

1
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 ]

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.