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 ...
随机推荐
- POJ 2441 Arrange the Bulls 状态压缩递推简单题 (状态压缩DP)
推荐网址,下面是别人的解题报告: http://www.cnblogs.com/chasetheexcellence/archive/2012/04/16/poj2441.html 里面有状态压缩论文 ...
- Restrictions用法
HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equal > Restrict ...
- 【spring data jpa】好文储备
[spring data jpa]带有条件的查询后分页和不带条件查询后分页实现 : https://blog.csdn.net/lihuapiao/article/details/48782843 ...
- python list 去掉重复元素
貌似用遍历最方便. http://www.cnblogs.com/tudas/p/python-delete-duplicate-element-from-list.html
- jsp servlet 进行基于js的用户验证
写这个只是完成使用js文件参数进行用户验证的处理的jsp 版,已经写过 asp.net php nodejs 以及纯js的,现在完善jsp的 使用的技术是比较简单的就是站点应用我们的js脚本,但是是带 ...
- CodeIgniter 安装指导
CodeIgniter 安装分为四个步骤: 解压缩安装包. 把 CodeIgniter 文件夹和里面的文件上传到你的服务器.通常 index.php 在根目录. 用任何文本编辑器打开 applicat ...
- SQL——ROW_NUMBER
版权声明:欢迎转载,请注明出处 https://blog.csdn.net/suneqing/article/details/30250193 语法: ROW_NUMBER() OVER(PARTIT ...
- nyoj 数独
数独 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 数独是一种运用纸.笔进行演算的逻辑游戏.玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一 ...
- Composer 技巧(以 FastAdmin 项目为基础)(2018-12-25 更新)
Composer 技巧(以 FastAdmin 项目为基础) 查看 FastAdmin 所有的已安装的 php 组件,如果不加 i 就是查看 composer.json 里的组件. composer ...
- gphoto2
连上usb线,系统会跳出detect到camera的提示,这里一定要选择“unmount”,否则会面的命令执行会有问题 hjs@ubuntu:~$ gphoto2 --auto-detect Mode ...