声的伟大!
分类: LINUX
2011-09-08 11:00:31
内容来源:哈哈-->http://chenxizhuimeng.blog.51cto.com
1)随机出现一个
#!/bin/bash
grep=(zhangping liubinbin maofang wangning dongyahui fanxingqiang wangjun yaohaiyang wangbo)
C=$[$RANDOM%9]
echo ${grep[$C]}
2)随机出现两个
#!/bin/bash
grep=(zhangping liubinbin maofang wangning dongyahui fanxingqiang wangjun yaohaiyang wangbo)
A=$[$RANDOM%9]
B=$[$RANDOM%9]
while [ $A -ge $B ] ; do
B=$[$RANDOM%9]
done
echo "${grep[$A]},${grep[$B]}"
3)融合:随机出现一个、两个到多个
vim test.sh
#!/bin/bash
grep=(zhangping liubinbin maofang wangning dongyahui fanxingqiang wangjun yaohaiyang wangbo)
flag=(0 0 0 0 0 0 0 0 0)
A() {
let T=1
while [ ! $T -eq 0 ]
do
B=$[$RANDOM%9]
if [ ${flag[$B]} -eq 0 ];then
echo "${grep[$B]}"
flag[$B]=$[${flag[$B]}+1]
T=0
fi
done
}
while getopts ":n:" SWITCH; do
case $SWITCH in
n) let I=$OPTARG
if [ $I -lt 10 -a $I -gt 0 ];then
while [ $I -gt 0 ]
do
A
I=$[$I-1]
done
else
echo "Please input a right number(1-8)." && exit 1
fi ;;
\?)echo "Please input :`basename $0` -n number(1-9)" && exit 1;;
esac
done