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