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

select用法

时间:2018-01-22 22:53:24      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:一个   实现   运行   and   cas   one   pre   UI   bash   

select也是循环的一种,它比较适合用在用户选择的情况下。
比如,我们有一个这样的需求,运行脚本后,让用户去选择数字,选择1,会运行w命令,选择2运行top命令,选择3运行free命令,选择4退出。脚本这样实现:

1. #!/bin/bash
2. echo "Please chose a number, 1: run w, 2: run top, 3: run free, 4: quit"
3. echo
4. select command in w top free quit
5. do
6.     case $command in
7.     w)
8.         w
9.         ;;
10.     top)
11.         top
12.         ;;
13.     free)
14.         free
15.         ;;
16.     quit)
17.         exit
18.         ;;
19.     *)
20.         echo "Please input a number:(1-4)."
21.         ;;
22.     esac
23. done

select用法

标签:一个   实现   运行   and   cas   one   pre   UI   bash   

原文地址:http://blog.51cto.com/amazing61/2063860

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