我一直在尝试在定义的数组中检查一个名称值上的 If Condition 。我遇到了这个错误:
main.sh: line 9: [10.247.78.207: command not found
main.sh: line 9: [10.247.78.207: command not found
这是我的代码:
#!/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
答案 0 :(得分: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
您需要[
和]
答案 1 :(得分:0)
将["${names[0]}" == "10.247.78.207"]
更改为[ "${names[0]}" == "10.247.78.207" ]
。这是[
之后和]
之前的空格。希望这能解决你的问题。