1创建抽奖名单
[root@yanyan ~]# cat luckypeople.txt
全宏妍
高硕
李颖
黄静
匡飞艳
王庭芳
陈露
陈文英
2.1用vim编辑器编写脚本
#!/bin/bash
friends=$(wc -l < luckypeople.txt )
num=$((RANDOM%$friends +1))
cat luckypeople.txt|head -$num|tail -1
2.2脚本
#!/bin/bash
friends_num=$(cat luckypeople.txt|wc -l) #统计luckypeople.txt中有多少人
num=$((RANDOM% friends_num + 1)) #根据统计的人数产生随机数
cat luckypeople.txt|head -$num|tail -1 #取随机数那行的人
3.运行脚本,进行抽奖
[root@yanyan ~]# bash happy.sh
王庭芳
[root@yanyan ~]# bash happy.sh
李颖
[root@yanyan ~]# bash happy.sh
匡飞艳
[root@yanyan ~]# bash happy.sh
陈文英
[root@yanyan ~]# bash happy.sh
全宏妍
[root@yanyan ~]# bash happy.sh
高硕