if语句不排除空字符串变量

时间:2014-07-01 04:05:02

标签: bash shell if-statement

我只是想知道(而且我很难过),为什么if语句不能正常工作。我错过了一些简单的东西吗?

#!/bin/bash

echo -e "\nFinding the thing things on the thing, presently.\n"

DEVICE=$1
IPADDRESS=$(/sbin/ifconfig $DEVICE | grep -A 0 'inet addr:' | cut -c21-29)

for i in {1..255}
do
    HOST=$(ping -c 1 $IPADDRESS.$i | grep -A 0 'from' | cut -c15-25)
    if ["$HOST" != ""]
    then
        echo "$HOST is ALIVE!!!"
    fi
done

1 个答案:

答案 0 :(得分:1)

您需要在:

之间添加空格
if [ "$HOST" != "" ]