码迷,mamicode.com
首页 > 其他好文 > 详细

随机挑几个--脚本

时间:2018-02-05 12:46:25      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:exp   set   nts   space   bin   ace   mes   exit   count   

#!/bin/bash # students=(Lilei Hanmeimei Lucy Lily Tom Jerry John Polly UncleWang) # ---------------------- premise ---------------------------- [ $# -eq 1 ] || exit [[ "$1" =~ [1-9] ]] || exit [ $1 -ge 1 -a $1 -le 9 ] || exit # ---------------------- Cycle $1 times -------------------- for ((i=1;i<=$1;i++)); do total=${#students[@]} rand=$(expr $RANDOM % $total) choice[${#choice[@]}]=${students[$rand]} unset students[$rand]=${students[$rand]} # --- exclude array student pace ---- # unset unspace for j in ${students[@]}; do [ -z "$j" ] && countinue unspace[${#unspace[@]}]=$j done students=(${unspace[@]}) ####### ####### done echo "Choice student: ${choice[@]}"

随机挑几个--脚本

标签:exp   set   nts   space   bin   ace   mes   exit   count   

原文地址:http://blog.51cto.com/sonlich/2068867

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!