Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10504855
  • 博文数量: 2905
  • 博客积分: 20098
  • 博客等级: 上将
  • 技术积分: 36298
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 05:00
文章存档

2012年(1)

2011年(3)

2009年(2901)

分类: LINUX

2009-03-23 11:10:52

 
 
 
判断两个文件内容是否相等,cmp也可以换成是diff
if cmp a b &> /dev/null # 阻止输出.
then echo "Files a and b are identical."
else echo "Files a and b differ."
fi
 
 
 
 
判断某个文本中是否含有某字符串的例子:if-grep 结构
 
 
# 非常有用的"if-grep" 结构:

if grep -q Bash file
then echo "File contains at least one occurrence of Bash."
fi
word=Linux
letter_sequence=inu
if echo "$word" | grep -q "$letter_sequence"
# "-q"选项是用来阻止输出
then
echo "$letter_sequence found in $word"
else
echo "$letter_sequence not found in $word"
fi
 

阅读(1055) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~