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

通常类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. CTF之猪圈密码

    猪圈密码又称济会密码,朱高密码,是一种简单的替代密码,所以安全性很低

  2. test20190320 全连(fc)

    题意 全连(fc) [题目背景] 还记得若干年前那段互相比较<克罗地亚狂想曲>的分数的日子吗? [题目描述] E.Space 喜欢打音游. 但是他技术不好,总是拿不到全连(Full Com ...

  3. AGC014E Blue and Red Tree

    题意 There is a tree with \(N\) vertices numbered \(1\) through \(N\). The \(i\)-th of the \(N−1\) edg ...

  4. Android USB gadget框架学习笔记

    一 Gadget框架结构 kernel/drivers/usb/gadget,这个目录是android下usbgadget的主要目录. Gadget功能组织单元:主要文件android.c,usb g ...

  5. C语言利用SMTP协议发送邮件

    #ifdef WIN32 #include <windows.h> #include <stdio.h> #else #include <stdio.h> #inc ...

  6. python之 序列与字典遍历

    在Python中有六种内建的序列:列表.元组.字符串.Unicode字符串.buffer对象和xrange对象.在这里暂时只讨论字符串.列表和元组的遍历. 一. 序列遍历 序列有两种遍历:一种通过值 ...

  7. CF 1013E Hills——隔项转移的DP

    题目:http://codeforces.com/contest/1013/problem/E 设 dp[ i ][ j ][ 0/1 ] 表示前 i 个位置,有 j 个山峰,第 i 个位置不是/是山 ...

  8. Zigbee 的 mesh功能设置

    1. 在编译选项中加入ZIGBEEPRO 最大的节点深度为20,网络模式为mesh网络 如果不配置,则为HOME_CONTROLS,支持5级路由深度,每个路由器最多可连接20个节点(最多包括6个路由器 ...

  9. lwip:与tcp发送相关的选项和函数

    1. 禁用Nagle tpcb->flags |= TF_NODELAY 2. tcp_write仅enqueue packet,而不会启动发送. 在tcp_write后调用tcp_output ...

  10. [转载]Linux下关于system调用

    曾经的曾经,被system()函数折磨过,之所以这样,是因为对system()函数了解不够深入.只是简单的知道用这个函数执行一个系统命令,这远远不够,它的返回值.它所执行命令的返回值以及命令执行失败原 ...