zoukankan      html  css  js  c++  java
  • linux case ${variable} in

    脚本实现划分考试等级层次;

    通常类unix系统下的压缩包的压缩程序类型不外乎是zip,gzip,bzip2这3中,现用file命令捕获Zip archive*,写出智能解压缩压缩包脚本如下;

    shell编程之case实例
    case结构如下;
    case ${variable} in
        ${variable}1)do something here or execute commands;;
        ${variable}2)do ;;
        ${n}) ;;
    esac

    ##############################################
    #linux智能解压包脚本
    #Create on 2013-07-23 by Qrui
    #【注,linux中一般的*.tar.gz,*.tar.gz2,*.zip等压缩文件都是经过gzip,zip,bzip2   这3个基本的压缩程序压缩创建的】
    #原理,我们使用linux下的file查看系统下面的文件类型
    来编程;
    ##############################################
    具体代码如下;

    #!/bin/sh
    #Create on 2013-07-23 by Qrui

    ftype="$(file "$1")"    //查看压缩文件的压缩类型,通常是Zip archive;gzip compressed;bzip2 compress;

    case "$ftype" in
        "$1: Zip archive"*)  //使用file捕获压缩包的压缩类型,"$1: Zip archive"*格式应和file查看到的相关的压缩格式一致
          unzip "$1" ;;     //执行智能解压
        "$1: gzip compressed"*)
          gunzip "$1" ;;
        "$1: bzip2 compress"*)
          bunzip2 "$1" ;;
    *) echo "Sorry, file $1 can not be uncompressed with this shell" ;;
    esac
    echo -n "Thanks take part in! bye."




    下面再举个对比脚本,使"$1: Zip archive"*)处的变量更直观,

    #!/bin/sh
    echo -n "enter a number from 1 to 3"
    read NUM
    case $NUM in
        1)echo "you select 1";;
        2)echo "you select 2";;
        3)echo "you select 3";;
        *)echo "basename $0 this is not between 1 and 5"
    esac

  • 相关阅读:
    STL 之 unordered_map
    vim tab和空格相互替换
    windows使用
    debugger打不开
    存储过程中执行动态Sql语句
    什么是详细设计说明书?
    C#中调用SQL存储过程(带输入输出参数的例子)
    如何解决网站在IE8下出现布局乱的情况?
    SQLServer 游标简介与使用说明
    线程池ThreadPoolExecutor参数设置
  • 原文地址:https://www.cnblogs.com/ruiy/p/case.html
Copyright © 2011-2022 走看看