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

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

linux case ${variable} in的更多相关文章

  1. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

  2. openwrt的uboot环境变量分析

    目前烧写完CC(chaos calmer 15.05)版本,查看其uboot变量如下: ath> printenvbootargs=console=ttyS0,115200 root=31:02 ...

  3. 鸟哥的私房菜:Bash shell(二)-变量的丰富功能

    一  Shell变量的取用与设定,变量规则 由于系统需要一些变量来提供他数据的存取,所以就有一些所谓的『环境变量』 需要来读入系统中了!这些环境变量例如 PATH.HOME.MAIL.SHELL.为了 ...

  4. 最简单的回射客户/服务器程序、time_wait 状态

    下面通过最简单的客户端/服务器程序的实例来学习socket API. echoser.c 程序的功能是从客户端读取字符然后直接回射回去.  C++ Code  1 2 3 4 5 6 7 8 9 10 ...

  5. gogodroid--android 上的IPV6工具

    gogodroid--android 上的IPV6工具 系统需求是 Android 1.6以上的系统,已经root,能够执行modprobe命令(在终端里输入modprobe,如果显示了帮助便可以), ...

  6. linux shell 报错 Syntax error: Bad for loop variable

    在linux下写了一个简单的shell,循环10次. test.sh #!/bin/bash ## ##循环10次 ## ; i<; i++)); do echo Good Morning ,t ...

  7. Linux启动应用(比如jmeter)报An error occurred: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

    Linux启动应用(比如jmeter)报An error occurred: Can't connect to X11 window server using ':0.0' as the value ...

  8. Linux下Tomcat启动报 The BASEDIR environment variable is not defined

    今天是2017年2月27.在Linux下部署Tomcat官网下载的Tomcat 8.5,结果启动startup.sh报如下错,即使只是跑version.sh也报同样的错. $ ./version.sh ...

  9. Linux - 简明Shell编程02 - 变量(Variable)

    脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash v1=test-variabl ...

随机推荐

  1. Unity 3D的常用快捷键

    Unity中的常用快捷键 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 Windows系统Unity3 ...

  2. CodeForces - 1087F:Rock-Paper-Scissors Champion(set&数状数组)

    n players are going to play a rock-paper-scissors tournament. As you probably know, in a one-on-one ...

  3. NASSA’s Robot

    NASSA的机器人降落到了火星,降落的地方可以用X-Y坐标表示.机器人最开始在(0, 0).由于传输问题,部分指令可能会混淆,现在给出确定的命令与未知命令,请帮忙确认机器人的X.Y坐标最小最大值分别是 ...

  4. dfs 与 剪枝

    http://blog.csdn.net/u010700335/article/details/44095171

  5. python之concurrent.futures模块

    一.concurrent.futures模块简介 concurrent.futures 模块提供了并发执行调用的高级接口 并发可以使用threads执行,使用ThreadPoolExecutor 或 ...

  6. selinux操作

    setenforce 0 关闭SELinux setenforce 1 临时打开SELinux getenforce 查看SELinux状态 永久关闭SELinux : # cat /etc/seli ...

  7. day34 python学习 守护进程,线程,互斥锁,信号量,生产者消费者模型,

    六 守护线程 无论是进程还是线程,都遵循:守护xxx会等待主xxx运行完毕后被销毁 需要强调的是:运行完毕并非终止运行 #1.对主进程来说,运行完毕指的是主进程代码运行完毕 #2.对主线程来说,运行完 ...

  8. gridview 自动序号 合计

    第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <asp:TemplateField HeaderText="序号" Ins ...

  9. smarty学习——变量

    变量的处理对于模板来说是比较重要的. Smarty有几种不同类型的变量. 变量 的类型取决于它的前缀是什么符号(或者被什么符号包围) Smarty的变量可以直接被输出或者作为函数属性和修饰符(modi ...

  10. NPOI控制Excel格式

    1.//sheet.SetColumnWidth(3, 50 * 256);  控制第三列宽,单位为1/256个字符 dataRow.Height = 18 * 20; 控制行高,单位为1/20点 s ...