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
linux case ${variable} in的更多相关文章
- Linux 驱动开发
linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...
- openwrt的uboot环境变量分析
目前烧写完CC(chaos calmer 15.05)版本,查看其uboot变量如下: ath> printenvbootargs=console=ttyS0,115200 root=31:02 ...
- 鸟哥的私房菜:Bash shell(二)-变量的丰富功能
一 Shell变量的取用与设定,变量规则 由于系统需要一些变量来提供他数据的存取,所以就有一些所谓的『环境变量』 需要来读入系统中了!这些环境变量例如 PATH.HOME.MAIL.SHELL.为了 ...
- 最简单的回射客户/服务器程序、time_wait 状态
下面通过最简单的客户端/服务器程序的实例来学习socket API. echoser.c 程序的功能是从客户端读取字符然后直接回射回去. C++ Code 1 2 3 4 5 6 7 8 9 10 ...
- gogodroid--android 上的IPV6工具
gogodroid--android 上的IPV6工具 系统需求是 Android 1.6以上的系统,已经root,能够执行modprobe命令(在终端里输入modprobe,如果显示了帮助便可以), ...
- linux shell 报错 Syntax error: Bad for loop variable
在linux下写了一个简单的shell,循环10次. test.sh #!/bin/bash ## ##循环10次 ## ; i<; i++)); do echo Good Morning ,t ...
- 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 ...
- Linux下Tomcat启动报 The BASEDIR environment variable is not defined
今天是2017年2月27.在Linux下部署Tomcat官网下载的Tomcat 8.5,结果启动startup.sh报如下错,即使只是跑version.sh也报同样的错. $ ./version.sh ...
- Linux - 简明Shell编程02 - 变量(Variable)
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash v1=test-variabl ...
随机推荐
- 原生JS 的cookie和jq的cookie,
COOKIE基础及应用:1.什么是COOKIE==>页面用来保存信息,比如:自动登录,记住用户名2.COOKIE的特性: --同一个网站中,所有的页面共享同一套cookie --数量,大小有 ...
- 状压dp终极篇(状态转移的思想)
状压dp是将每种状态都压缩成用一个二进制串,然后利用位运算进行操作的dp,而凡是dp都需要进行状态转移 对于简单的dp问题只需要一个二维数组dp[ i ][ j ]就能解决 具体操作为首先把状态压缩为 ...
- test20180829
试题限制均为128MB,1Sec 总分150. 试题一 A题 问题描述: 小A得到了一棵美丽的有根树.这棵树由n个节点以及n - 1条有向边构成,每条边都从父亲节点指向儿子节点,保证除了根节点以外的每 ...
- nexage video asset tag
video ad can't show InLine must match the example ,and xml content is Case Sensitive https:/ ...
- 转 JavaScript中判断对象类型的种种方法
我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...
- 走进windows编程的世界-----消息处理函数(1)
Win32消息机制 过程驱动:程序是依照我们预先定义好的顺序运行.每运行一步,下一步都已经依照预定的顺序 继续运行,直至程序结束. 事件驱动:程序的运行顺序是无序的.某个时间点所运行的 ...
- bat删除系统默认共享
在我们的系统中,有很多默认的共享是开启的,可以设置一个bat文件在每次开机的时候把共享删除. net share c$ /del net share d$ /del net share e$ /del ...
- jquery 1.9里面已经删除了toggle(fn1, fn2)函数:
jquery 1.9里面已经删除了toggle(fn1, fn2)函数:引用Note: This method signature was deprecated in jQuery 1.8 and r ...
- java 多线程之:wait()、notify()、notifyAll()等方法
wait().notify().notifyAll()等方法介绍: 在Object.java中,定义了wait(), notify()和notifyAll()等接口.wait()的作用是让当前线程进入 ...
- mysql 中find_in_set()和in()用法比较
mysql 中find_in_set()和in()用法比较 在mysql中in可以包括指定的数字,而find_in_set()用于特定的数据类型. find_in_set 函数使用方法 个例子来说:有 ...