• 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

  • 相关阅读:
    day01-h1字体大小和文本居中
    js正则表达式中的
    js滚动分页原理
    在web.xml中设置全局编码
    C# 导出word 表格代码
    C# 创建单例
    Winform 异步调用2 时间
    Winform 异步调用
    c#中跨线程调用windows窗体控件
    C# 中的委托和事件
  • 原文地址:https://www.cnblogs.com/ruiy/p/case.html
Copyright © 2020-2023  润新知