1. 在shell 中每個命令執行後都會返回0代表命令執行失敗,返回1代表命令執行成功,我們可以利用這個特性處理類似exception的功能判斷
逐行 遍歷 文件 內容
2. bbtv launch shell
#show all files in a folder, include the files in its subfolder
find ${sourceFolder} -type f -printf "%p /n" | awk -F"${sourceFolderName}/" '{print $2}' > ${files}
#show current folder's structure.
cd ${sourceFolder}
ls -lR | grep ./ | sed -e 's/.' | sed 's/://' > ${folders}
#create the source folder's structure in the backup folder
while read LINE;
do
echo ${LINE}
mkdir -p ${backupFolder}/${sourceFolderName}/${LINE}
done < ${folders}
3. 遍歷目錄文件
for folder in `ls`
do
cd ${folder}
echo "${folder}"
num=`ls detail-* | wc -l`
if [ $num -gt "0" ]
then
tmp=`grep 'Acct-Status-Type = Start' detail-* | wc -l`
tmp1=`grep 'NAS-Identifier =' detail-* | awk -F"=" '{print $2}' | sort | uniq`
tmp2=`echo ${tmp1} | grep /"*/"`
`echo ${tmp2}" , "${tmp} >> ${file}`
fi
cd ..
done
4. 注意
4.1 如果在 if 判斷條件中包含命令, 那麼要用 ``把這些命令包含起來
4.2 每個命令執行後都會有一個返回信息,我們可以通過 echo $? 來查看這個命令是否正常執行