[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";}'