zoukankan      html  css  js  c++  java
  • Linux Gvim shell case...esac语句

    #case ..esac语句:与switch ..case类似,是一种多分支选择结构
    #case语句匹配一个值或一个模式,如果匹配成功执行相应命令,如果匹配不成功执行*命令
    #;;与break类似,代表跳到整个case语句的最后
    #case 值 in
    #模式1)
    #    command1
    #    ;;
    #模式2)
    #    command1
    #    ;;
    #*)
    #    command1
    #    ;;
    #esac
    #示例如下:

     1 echo 'Input a number between 1 to 4'
     2 echo -e 'Your number is:c'
     3 read aNum
     4 case $aNum in
     5         1)  echo 'You select 1'
     6         ;;
     7         2)  echo 'You select 2'
     8         ;;
     9         3)  echo 'You select 3'
    10         ;;
    11         4)  echo 'You select 4'
    12         ;;
    13         *)  echo 'You do not select a number between 1 to 4'
    14         ;;
    15 esac

    #测试输入xxx.sh -f index.html or xxx.sh -d unix 此时进入×)输出

     1 option="${1}"
     2 case ${option} in
     3    -f) FILE="${2}"
     4       echo "File name is $FILE"
     5       ;;
     6    -d) DIR="${2}"
     7       echo "Dir name is $DIR"
     8       ;;
     9    *) 
    10       echo "`basename ${0}`:usage: [-f file] | [-d directory]"        #如果都不是,则执行xxx.sh#
    11       exit 1 # Command to come out of the program with status 1
    12       ;;
    13 esac
  • 相关阅读:
    LeetCode(6. Z 字形变换)
    二分查找
    线性查找
    平安寿险Java面试-社招-四面(2019/08)
    希尔排序
    中移物联网Java面试-社招-三面(2019/07)
    插入排序
    选择排序
    冒泡排序
    八皇后问题
  • 原文地址:https://www.cnblogs.com/blog4matto/p/5572031.html
Copyright © 2011-2022 走看看