www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

 

通常类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

posted on 2013-07-23 13:54  秦瑞It行程实录  阅读(589)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui