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
  • 相关阅读:
    &与&&的区别
    x^y=(x&~y)|(~x&y)证明
    a、b交换与比较
    x+y = ((x&y)<<1) + (x^y) 证明
    (x&y) + ((x^y)>>1)即x和y的算数平均值
    默认参数提升
    类型转换
    闲扯原码,补码和反码(转)
    C/C++中float和double的存储结构
    led设备驱动(s3c_led.c)
  • 原文地址:https://www.cnblogs.com/blog4matto/p/5572031.html
Copyright © 2011-2022 走看看