shell中的fi表示一個(gè)if語句握陪的結(jié)尾,例如:
成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、武侯網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5技術(shù)、購物商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為武侯等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
if [ command ];then
符合該條件執(zhí)行的語句
elif [ command ];then
符合橘皮旁該條件執(zhí)行的語句
else
符合圓橡該條件執(zhí)行的語句
fi
#!/bin/bash
if [ ! -f check.txt ];then
ls check.txt
elif [ ! -f check.old ];then
mv check.txt check.old
ls check.txt
diff check.txt check.old|grep '^'|sed 's//deleted file:/g'
diff check.txt check.old|grep '^'|sed 's/斗虛/created file:/g'
else
mv check.txt check.old
ls check.txt
diff check.txt check.old|grep '^'|sed 's//deleted file:/g'
diff check.txt check.old|grep '^'|sed 's//created file:/g'
fi
不知是不是你空談燃想侍沒要的。。。只實(shí)現(xiàn)監(jiān)控新增的文件和刪除的文件。
我分享一個(gè)2個(gè)數(shù)運(yùn)笑字的SHELL 你可以舉一反三《Linux就該這么學(xué)》中有個(gè)Linux命令大全
#1.判斷是不是兩個(gè)數(shù)
[ $# -ne 2 ] {
echo "Usage:$0 num1 num2"
exit 1
}
#2.判斷旦悄賣是模逗否為數(shù)字
expr $1 + $2 + 999 /dev/null
[ $? -ne 0 ] {
echo "請輸入兩個(gè)整數(shù)"
exit 2
}
if [ $1 -gt $2 ]
then
echo "$1$2"
elif [ $1 -lt $2 ]
then
echo "$1$2"
else
echo "$1=$2"
fi
========================
read -p "please two number: " a b
expr $a + $b + 999 /dev/null
if [ $? -ne 0 ]
then
echo "請輸入兩個(gè)整數(shù)"
exit 1
else
if [ $a -gt $b ]
then
echo "$a$b"
elif [ $a -lt $b ]
then
echo "$a$b"
else
echo "$a=$b"
fi
fi
#!/bin/bash#格式化過期日期,格式化過期日期完整時(shí)間以當(dāng)前時(shí)間作為參考!expday="2018-04-11 `date +%T`"echo "Expire day is $expday"#當(dāng)前日期時(shí)間格式為stamp時(shí)間戳todays=`date +%s`echo "Today is $(date +"%F %T")"#以下2種方式做時(shí)間的四鎮(zhèn)沖圓則運(yùn)算,分別使用 let 或者 $(( ))#過期日期已格式化,規(guī)避整數(shù)運(yùn)算的誤差(去余數(shù))#let dayDiff=($(date -d "御塌$expday" +%s)-$todays)/86400dayDiff=$(( ($(date -d "$expday" +%s)-$todays)/86400 ))echo "Diff day is $dayDiff days!"
其余說明:
bash 不支持浮點(diǎn)運(yùn)算,如果需要進(jìn)行浮點(diǎn)運(yùn)算,需要借助bc,awk 處理。Linux命令需求的話可如下圖進(jìn)判銀行查詢