点名器初始版

punishment(){
cat <<EOF
=========================================================
= 1、 大喊李世杰万岁 =
= 2、 去隔壁班门口二十个俯卧撑 =
= 3、 表演胸口碎大石 =
= 4、 来段单口相声 =
= 5、 跟宋世雄比抽烟 =
=========================================================
EOF
read -p "选你相中的惩罚吧:" number
if [ $number -eq 1 ];then
echo "${name}的惩罚大喊李世杰万岁,这都不喊,欺我组长太甚" >>./records.txt
elif [ $number -eq 2 ];then
echo "${name}的惩罚去隔壁班门口二十个俯卧撑,未完成" >>./records.txt
elif [ $number -eq 3 ];then
echo "${name}的惩罚表演胸口碎大石,未完成" >>./records.txt
elif [ $number -eq 4 ];then
echo "${name}的惩罚来段单口相声,未完成" >>./records.txt
elif [ $number -eq 5 ];then
echo "${name}的惩罚跟宋世雄比抽烟,未完成" >>./records.txt
else
echo "请正确使用脚本"
exit
fi
}
give_name(){
name=""
while [ -z "$name" ]
do
name_id=`echo $((RANDOM%38+1))`
name=`fgrep "[$name_id]" ./name.txt | awk '{print $2}' `
done
echo "有请嘉宾$name"
}
init(){
if [ -z "`cat ./name.txt`" ];then
\cp ./name.back ./name.txt && \
> ./records.txt
echo "第一轮循环结束,正在初始化信息表,开启下一轮"
fi
}
read -p "是否初始化名单表,请输入[yes|no]" choice
if [ "$choice" = "yes" ];then
\cp ./name.back ./name.txt && \
> ./records.txt
fi
a=`awk 'END{print NR}' ./name.txt`
i=0
while [ $i -le $a ]
do
problem_id=`echo $((RANDOM%7+1))`
problem=`grep $problem_id ./problem.txt | awk '{print $2}'`
answer=`grep $problem_id ./problem.txt | awk '{print $3}'`
init
echo "开始点名"
sleep 2
give_name
read -p "请听题,${problem} :" result
if [ "$result" != "$answer" ];then
punishment
read -p "请输入是否完成惩罚[yes|no]" num
if [ "$num" = "yes" ];then
sed -i '/${name_id}/d' ./records.txt
sed -i '/'$num'/d' ./records.txt
echo "不错,我就知道你行的,下课点一根去~~~~~~~"
else
echo "ok,记下来了,发杰哥邮箱去;"
tail -n 1 ./records.txt | mail -s "不好好做惩罚,求处置" 18894431968@163.com
fi
fi
sed -i '/'"$name"'/d' ./name.txt && \
let i++
sleep 2
read -p "是否继续点名呢:[yes|no]": inquire
if [ "${inquire}" = "yes" ];then
echo "ok,继续来"
elif [ "${inquire}" = "no" ];then
exit
else
echo "还想继续,很好"
fi
sleep 1
done

此作者没有提供个人介绍
最后更新于 2024-11-09