LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1426|回复: 4

请问这个shell脚本哪里错了,判断IP地址的

[复制链接]
发表于 2007-5-1 22:52:13 | 显示全部楼层 |阅读模式
#!/bin/bash
t1="192.168.2.3"
t2="192,168,2,25"
if [ $t1 -ne $t2 ]
then
echo "t1 in fact is $t1"
fi

[root@rhel ~93]#cat nu
#!/bin/bash
t1="192.168.2.3"
t2="192,168,2,25"
if [ $t1 -ne $t2 ]
then
echo "t1 in fact is $t1"
fi
[root@rhel ~94]#./nu
./nu: line 4: [: 192.168.2.3: integer expression expected
[root@rhel ~95]#

请问是哪里错了
发表于 2007-5-2 04:17:40 | 显示全部楼层
-ne,-gt,-lt,etc is for comparing integer. use "=", "!=", etc instead for string.
回复 支持 反对

使用道具 举报

发表于 2007-5-2 07:40:27 | 显示全部楼层
斑竹归来,赞!
回复 支持 反对

使用道具 举报

发表于 2007-8-30 11:06:19 | 显示全部楼层
#!/bin/bash
t1="192.168.2.3"
t2="192.168.2.25"
if [ $t1 != $t2 ]; then
echo "OK"
fi
回复 支持 反对

使用道具 举报

发表于 2007-9-23 00:08:09 | 显示全部楼层
楼上的,说的对。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表