1. [root@old_boy scripts]# cat judgehost.sh   

  2. #!/bin/bash  

  3. echo "please input ip address:" 

  4. read ip  

  5. [ -n "`grep "$ip " /etc/hosts`" ] && \  #注意前面的过滤条件结尾带有空格。  

  6. echo "The hostname is: `grep "$ip " /etc/hosts |awk '{print $2}'`" || \  

  7. echo "The ip is invalid" 

[ -n "ddd" ] && echo 1 || echo 0


三元运算符


awk 'BEGIN{a="b";print a=="b"?"ok":"err";}'