20 - sed综合案例

点名器

  • 新建名单文件
echo 'jack' > name.txt
$ echo 'kevin' >> name.txt
$ echo 'monica' >> name.txt
$ echo 'amy' >> name.txt
$ echo 'lily' >> name.txt
  • 编写随机点名脚本
#!/bin/bash
#function description: random pick a name, stop with CTRL + C
name_file="name.txt"
line_file=$(sed -n '$=' $name_file)
while :
do
  #clear
  tmp=$(sed -n "$[RANDOM%line_file+1]p" $name_file)
  echo -e "\033[32m   random pick name, stop with CTRL+C: \033[0m"
  echo -e "\033[32m###############################\033[0m"
  echo -e "\033[32m#                    #\033[0m"
  echo -e "\033[32m           $tmp         \033[0m"
  echo -e "\033[32m#                    #\033[0m"
  echo -e "\033[32m##############################\033[0m"
  sleep 0.5
done

你可能感兴趣的:(20 - sed综合案例)