#!/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. 13.Query for Null or Missing Fields-官方文档摘录

    1 插入数据 db.inventory.insertMany([ { _id: 1, item: null }, { _id: 2 } ]) 2 查询null值 db.inventory.find({ ...

  2. iOS开发- 速学Swift-中文概述

    Swift是什么? Swift是苹果于WWDC 2014公布的编程语言,这里引用The Swift Programming Language的原话: Swift is a new programmin ...

  3. 0604-Zuul构建API Gateway-Zuul的回退

    一.概述 参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#hystrix-f ...

  4. Java集合—Set(转载)

    Set集合中包含了三个比较重要的实现类:HashSet.TreeSet和EnumSet.本篇文章将重点介绍这三个类. 一.HashSet类 HashSet简介 HashSet是Set接口的典型实现,实 ...

  5. nginx配置ThinkPHP5二级目录访问

    可以通过 http://www.mracale.com/项目名/模块名/方法名 进行访问 第一步 首先,你要确保在不配置二级目录的情况下,可以通过浏览器访问到.例如:http://www.mracal ...

  6. LVS-DR 配置测试

    LVS Lvs体系结构 Lvs工作模式(3种) NAT-网络地址转换模式 当用户请求到达调度器时,调度器将请求报文的目标地址(即虚拟IP地址)改写成选定的Real Server地址,同时报文的目标端口 ...

  7. 工作笔记-javascript-网络层封装

    /** * @Author Mona * @Date 2016-12-08 * @description 网络层封装 */ /** * 封装基本请求方式 */ window.BaseRequest = ...

  8. JAVA_HOME is not defined correctly

    这是个神奇的问题.系统运行着运行着,突然就挂了.各种Java包丢失. 1.检查maven配置 .bash_profile   2.检查运行调取文件  .mavenrc 运行 java -version ...

  9. 32. Longest Valid Parentheses(最长括号匹配,hard)

      Given a string containing just the characters '(' and ')', find the length of the longest valid (w ...

  10. centos ssh免密码秘钥登录

    假设从A主机ssh登录B主机,用秘钥代替密码,步骤如下: 1.在A主机上执行:ssh-keygen -t  rsa 一切默认,不用输入密码,生成两个文件: /root/.ssh/id_rsa /roo ...