shell脚本专家指南--比较的基本原理

来源:互联网 发布:华为波士顿矩阵分析 编辑:程序博客网 时间:2024/05/28 06:05

比较的基本原理
 if [ "$FILE"="aaa" ]
 then
  echo "something1"
 else   
  echo "something2"
 fi 
 左方括号"["是shell的一个内部命令
 和test命令类似
  if test "$FILE"="aaa"
  then ...

 test "$FILE"="aaa" && echo "they are eq"
 [ "$FILE"="aaa" ] && {
  echo "en eq"
 }
 性能上无差别
 test "$FILE"="aaa" || echo "they are eq"

 右括号表示比较完成,根据命令返回码比较是否为真
 
 执行命令作为条件
 if [ "`grep nodename /etc/hosts`" ];then ...