Skip to content

Instantly share code, notes, and snippets.

@andyhuzhill
Last active August 29, 2015 14:07
Show Gist options
  • Save andyhuzhill/54cf878a46d04ba53f77 to your computer and use it in GitHub Desktop.
Save andyhuzhill/54cf878a46d04ba53f77 to your computer and use it in GitHub Desktop.
#! /bin/bash
# *-* encoding: utf-8 *-*
#
# =============================================
#
# Author : Andy Scout
# E-mail : andyhuzhill@gmail.com
#
# Description : 在文件夹中递归的进入每个子目录,
# 校验每个子目录下生成校验文件
# Revision :
#
# =============================================
# 全局变量记录递归层数
nest=0
# 记录脚本参数
option=$1
if [ ! "$option" ]
then
echo "Usage : ./makeshasum [make][clean][verify]"
exit 1
fi
function dosha512sum() {
local files=$(ls -1)
case $option in
"make")
sha512sum * > file.sha512 ;;
"clean")
rm file.sha512 ;;
"verify")
sha512sum -c file.sha512 ;;
esac
for file in $files
do
if [ -d $file ]
then
cd $file
nest=$[nest+1]
dosha512sum
fi
done
if [ $nest -ne 0 ]
then
cd ..
nest=$[nest-1]
return
fi
}
dosha512sum
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment