当前位置:首页 » Linux技术知识

随机生成8位字符串函数

2017-12-04 17:00 本站整理 浏览(1)

啊啊

# 随机生成8位字符串函数randstr
randstr() {
  index=0
  str=""
  for i in {a..z}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {A..Z}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {1..8}; do str="$str${arr[$RANDOM%$index]}"; done
  echo ${str}
}

echo `randstr`