#!/bin/bash
# case echo "1.Install PHP"
echo "2.Install Mysql"
echo "3.Install Nginx" read -p "please input your digit:" digit case "$digit" in
"1" )
echo "Install PHP"
#输出两个分号
;;
"2" )
echo "Install Mysql"
;;
"3" )
echo "Install Nginx"
;;
* )
#其它输入
echo "Error"
;;
esac

运行结果

# sh case.sh
1.Install PHP
2.Install Mysql
3.Install Nginx
please input your digit:1
Install PHP

结合select做选择菜单。

#! /bin/bash
# case
PS3="Select your digit:"
select i in "Install PHP" "Install Mysql" "Install Nginx"
do case $i in
"Install PHP" )
echo "Install PHP"
#输出两个分号
;;
"Install Mysql" )
echo "Install Mysql"
;;
"Install Nginx" )
echo "Install Nginx"
;;
* )
#其它输入
echo "Error"
;;
esac
done

执行的时候,必须用bash来执行。

# /bin/bash case.sh
1) Install PHP
2) Install Mysql
3) Install Nginx
Select your digit:1
Install PHP
Select your digit:2
Install Mysql
Select your digit:3
Install Nginx
Select your digit:4
Error
Select your digit:^C

shell脚本中case select 的使用的更多相关文章

  1. [转]Shell脚本中获取SELECT结果值的方法

    http://blog.itpub.net/13885898/viewspace-1670297/ 有时候我们可能会需要在Shell脚本中执行SELECT语句,并将结果赋值给一个变量,对于这样的情形, ...

  2. shell脚本中case的用法

    shell脚本中case选择语句可以结合read指令实现比较好的交互应答操作,case接收到read指令传入的一个或多个参数,然后case根据参数做选择操作. case的语法如下 case $char ...

  3. Shell脚本中获取select值

    最近做一个数据清理,根据行号清理,所以需要查出这个行的最大最小值出来进行删除,如果靠手动每次去查,太麻烦所以就用在sh脚本当中执行SELECT语句,并将结果赋值给一个变量. sh脚本如下 #! /bi ...

  4. shell脚本中case /*的作用

    如下语句 case $0 in /*) ;; *) ;; /*在这里的作用就是绝对路径的意思

  5. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  6. shell脚本中select循环语句用法

    shell脚本中select循环语句 1. 脚本中select的语法格式 select VAR in LIST do command1 command2 ... ... commandN done s ...

  7. Shell脚本中的逻辑判断、文件目录属性判断、if的特殊用法、case判断

    1.Shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi格式2:if 条件; then 语句; else 语句; fi格式3:if …; then … ;elif …; then ...

  8. shell脚本中的逻辑判断、文件目录属性判断、if特殊用法、case判断

    7月12日任务 20.5 shell脚本中的逻辑判断20.6 文件目录属性判断20.7 if特殊用法20.8/20.9 case判断 20.5 shell脚本中的逻辑判断 逻辑判断在shell中随处可 ...

  9. Linux centosVMware shell脚本中的逻辑判断、文件目录属性判断、if特殊用法、case判断

    一.shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi 格式2:if 条件; then 语句; else 语句; fi 格式3:if …; then … ;elif …; th ...

随机推荐

  1. linux定时任务常用命令大全

    脚本中时间戳 TIMESTAMP=`date +%Y%m%d%H%M%S`

  2. shell_03

    函数: fanction print_welcome(){ echo welcome now time is `date` } print_welcome 函数调用 print _welcome 00 ...

  3. Art of Android Develop. Activity的生命周期和启动模式。

    1.  onCreate() ,  onRestart(),  onStart(),  onResume(),  onPause(),  onStop(),  onDestroy() 2.

  4. linux根文件系统 /etc/resolv.conf 文件详解(转)

    大家好,今天51开源给大家介绍一个在配置文件,那就是/etc/resolv.conf.很多网友对此文件的用处不太了解.其实并不复杂,它是DNS客户机配置文件,用于设置DNS服务器的IP地址及DNS域名 ...

  5. Boinformatics-2018-10-1-目录

    1.基因分析 --Using standard microbiome reference groups to simplify beta-diversity analyses and facilita ...

  6. PAT 1078 Hashing[一般][二次探查法]

    1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive integ ...

  7. node+express+http-proxy-middleware做代理

    最近,不赶着做项目,于是想着怎样做公司的前后端分离,这个时候想到了nodejs,于是打算今天做一个代理的demo,其实代码很简单,但是一直卡在一个地方,现在问题解决了,贴上代码和截图. html &l ...

  8. Android中三种超实用的滑屏方式汇总(转载)

    Android中三种超实用的滑屏方式汇总   现如今主流的Android应用中,都少不了左右滑动滚屏这项功能,(貌似现在好多人使用智能机都习惯性的有事没事的左右滑屏,也不知道在干什么...嘿嘿),由于 ...

  9. bootstrap模态框嵌套、tabindex属性、去除阴影

    模态框嵌套 在开发中,遇到需要通过点击事件触发第一个模态框,触发后通过事件唤起第二个模态框,并且通过事件触发第三个模态框:即模态框嵌套. 模态框嵌套需要用一个模态框包裹所涉及嵌套的模态框,从而点击触发 ...

  10. XDU 1130 (快速幂)

    题目大意:原题链接 解题思路:sum((p+i*d)*C(n,i))=sum(p*C(n,i)+d*i*C(n,i)) ; 又因为i*C(n,i)=n*C(n-1,i-1) 所以sum((p+i*d) ...