經(jīng)過(guò)約5天的時(shí)間,老師就將shell腳本講完了,明天要正式講C但是我仍然是一臉懵逼,不知所措。
經(jīng)過(guò)這五天的接觸也能感覺(jué)到,只有多多練習(xí)才有可能敲出來(lái)自己的東西,自己雖然從早到晚也在跟著老師敲命令,但是效率低下,也想快速提高效率。
今天老師主要給我們演示了三段命令,只有第三段的sed -i 's/old/new/g' xx.txt是一個(gè)新命令,用來(lái)替換已有文件內(nèi)的內(nèi)容的,其他額度都是之前講到過(guò),我自己就是不能夠把他們串到一起,甚至寫(xiě)出單個(gè)命令都有困難。
這是一段“萬(wàn)年歷”命令,但是只能顯示本月1月份的,輸入其他月份會(huì)出錯(cuò)
printCal
{
year=$1
month=$2
allDay=0
i=1990
array=(0 31 0 31 30 31 30 31 31 30 31 30 31)
while [ $i -lt $year ]
do
if [[ `expr $i % 4` == 0 && $((i%100)) != 0 ]] || [ `expr $i % 400` == 0 ]
then
let allDay=allDay+366
else
let allDay=allDay+365
fi
let i++
done
if [[ `expr $year % 4` == 0 && $((year%100)) != 0 ]] || [ `expr $year % 400` == 0 ]
then
array[2]=29
else
array[2]=28
fi
i=1
while [ $i -lt $month ]
do
let allDay=allDa+array[i]
let i++
done
let allDay=allDay+1
#week是記錄星期幾
let week=allDay%7
echo "=====${year}--${month}====="
printf "日\(chéng)t一\t二\t三\t四\t五\t六\n"
blank=1
colum=0
while [ $blank -le $week ]
do
printf " \t"
let blank++
let colum++
done
i=1
while [ $i -le ${array[$month]} ]
do
printf "$i\t"
let i++
let colum++
if [ `expr $colum % 7` == 0 ]
then
printf "\n"
fi
done
if [ `expr $colum % 7` != 0 ]
then
printf "\n"
fi
}
if [ $# -eq 0 ]
then
year=`date +%Y`
month=`date +%m`
elif [ $# -eq 1 ]
then
echo "軟件正在完善中..."
elif [ $# -eq 2 ]
then
year=$1
month=$2
else
echo "參數(shù)過(guò)多!!!"
fi
printCal $year $month
這是老師帶我們寫(xiě)的一段vi命令,據(jù)說(shuō)這個(gè)命令對(duì)以后寫(xiě)c命令有幫助,不明覺(jué)厲,
fileName=$1
year=`date +%Y`
month=`date +%m`
day=`date +%d`
createTime="$year\/$month\/$day"
if [ $# -eq 0 ]
then
echo "請(qǐng)輸入文件名!!!"
elif [ $# -eq 1 ]
then
if [ -d ./${fileName} ]
then
echo "該文件是目錄文件!!!"
else
length=${#fileName}
let start=length-2
suffix=${fileName:start:2}
if [ $suffix = ".c" ]
then
if [ -e ./${fileName} ]
then
currentTime=`date +%k:%M:%S`
lastChangeTime="lastChangeTime:${createTime}-${currentTime}"
sed -i "" "s/lastChangeTime\.*/${lastChangeTime}/g" ./${fileName} ? #一般-i后面的“”雙引號(hào)可以去掉
vi ./${fileName}
else
cp ~/prepare.txt ./prepare.c
mv prepare.c ${fileName}
sed -i "" "s/fileName/${fileName}/g" ./${fileName}? ? ? ? ? ? #一般-i后面的“”雙引號(hào)可以去掉
sed -i "" "s/createTime/${createTime}/g" ./${fileName}? ? ? #一般-i后面的“”雙引號(hào)可以去掉
sed -i "" "s/lastTime/${createTime}/g" ./${fileName}? ? ? ? ? ? #一般-i后面的“”雙引號(hào)可以去掉
currentTime=`date +%k:%M:%S`
lastChangeTime="lastChangeTime:${createTime}-${currentTime}"
sed -i "" "s/lastChangeTime\.*/${lastChangeTime}/g" ./${fileName}? ? #一般-i后面的“”雙引號(hào)可以去掉
vi ./${fileName}
fi
fi
fi
else
echo "參數(shù)過(guò)多!!!"
fi
之前有位朋友提到過(guò)讓我在筆記中做注釋,今天仔細(xì)一看,不是不寫(xiě),而是不知道怎么寫(xiě),寫(xiě)什么,如果一定需要注釋,我只好給自己注釋:所有命令再敲個(gè)十幾二十遍,最后還要能換著花樣敲,才算合格,因?yàn)槲覍?shí)在不知該如何應(yīng)用,而且明天就是C了,這些內(nèi)容只能課后抽空自己練習(xí)。