-
[root@old_boy scripts]# cat judgehost.sh
-
#!/bin/bash
-
echo "please input ip address:"
-
read ip
-
[ -n "`grep "$ip " /etc/hosts`" ] && \ #注意前面的过滤条件结尾带有空格。
-
echo "the hostname is: `grep "$ip " /etc/hosts |awk '{print $2}'`" || \
-
echo "the ip is invalid"
[ -n "ddd" ] && echo 1 || echo 0
三元运算符
awk 'begin{a="b";print a=="b"?"ok":"err";}'