17:天津项目学生实践抓阄案例

[root@jenkins scripts]# cat zhuajiu.sh 
#!/bin/bash
##############################################################
# File Name: zhuajiu.sh
# Version: V1.0
# Author: gaobo
# Organization: 641627690@qq.com
# Created Time : 2017-12-10 15:24:48
# Description:
##############################################################
msg_file=/tmp/cc.txt
>${msg_file}
[ -f ${msg_file} ] || touch /tmp/cc.txt &>>/dev/null

while true
do
read -p "输入一姓名:" name
[ $(echo "${name}"|grep "[^a-z]"|wc -l) -gt 0 ] && echo "名字不能包含非字母" && continue
[ $(egrep $name ${msg_file}|wc -l) -gt 0 ] && echo "名字存在已选号" && continue
[ $(wc -l ${msg_file}|awk '{print $1}') -eq 10  ] && echo "6位同学是" && sort -rnk2 /tmp/cc.txt|head -6 && exit 0



while true
do
    [ $(wc -l ${msg_file}|awk '{print $1}') -ge 10 ] && break 2 #随机数超过100,不让随机

    ct=$(echo "$RANDOM/100"|bc)
    [ $(egrep  ${ct}  ${msg_file}|wc -l) -gt 0 ] && continue   #预防随机相同的数
    echo "$name    ${ct}" >>${msg_file}
    #sleep 3
    break
    
done

done

 天津项目学生实践抓阄案例

好消息,老男孩培训学生外出企业项目实践机会(第6次)来了(本月中旬),但是,名额有限,队员限3人(班长带队)。

因此需要挑选学生,因此需要一个抓阄的程序:

要求:

1、执行脚本后,想去的同学输入英文名字全拼,产生随机数01-99之间的数字,数字越大就去参加项目实践,前面已经抓到的数字,下次不能在出现相同数字。

2、第一个输入名字后,屏幕输出信息,并将名字和数字记录到文件里,程序不能退出继续等待别的学生输入。  解答:

原文地址:https://www.cnblogs.com/gaoyuechen/p/8017365.html