命令行参数传递:lucky a b c d e g h
文件获取清单: lucky < xxx.txt
管道获取清单: echo a b c d | lucky
lucky(){
let count=0
if [ $# -lt 1 ]
then
pro_name=($(cat $1))
else
pro_name=$@
fi
while true
do
echo ${pro_name[@]}
winner=()
for i in ${pro_name[@]}
do
if [ $((RANDOM%6+1)) -ge 3 ]
then winner+=($i)
fi
done
let count++
if [[ ${#winner[@]} -gt 1 ]]
then
pro_name=(${winner[@]})
echo "第$count轮胜出人员:"${winner[@]}
elif [ ${#winner[@]} -eq 1 ]
then
echo "第$count轮胜出人员:"${winner[@]}
echo "最终获胜者:"${winner[@]}
break;
else
echo "第$count轮无获胜者,重新比赛!"
fi
done
}
lucky(){
Namelist=$(cat name_list.txt)
round=0
while true
do
let round+=1
echo "round:$round" "member:${Namelist[*]}"
i=0
pass_list=()
for member in ${Namelist[*]}
do
result=$((RANDOM%6+1))
if [ $result -gt 3 ]
then
pass_list[$i]=$member
let i+=1
fi
done
if [ $i == 0 ]
then
continue
elif [ $i == 1 ]
then
echo "winner:${pass_list[0]}"
break
else
Namelist=${pass_list[*]}
continue
fi
done
}
lucky
count=1
while true
do
winner=()
for i in ${seeds[@]}
do
if [ $((RANDOM%6+1)) -gt 3 ]
then winner+=($i)
fi
done
echo “第“$count”轮胜出的人员是:”${winner[@]}
((count++))
if [ ${#winner[@]} -eq 0 ]
then winner=$seeds
else seeds=$winner
fi
if [ ${#winner[@]} -eq 1 ]
then break
fi
done
echo “幸运中奖者是:”${winner[@]}