【Bash脚本】处理命令行入参
来源:互联网 发布:雪饮刀淘宝 编辑:程序博客网 时间:2024/05/18 02:48
主要利用getopt对参数进行检查,然后循环找到各个参数。
#!/bin/bashfunction printUsage { echo "Usage:" echo "$0 <src> <dst> [-f format] [-s setting]"}params=`getopt f:s: "$@"`if [ $? != 0 ] ; then echo "Invalid arguments." printUsage >&2 exit 1;fiParaFormat="defaultFormat"ParaSetting="defaultSetting"eval set -- "$params"while true; do case "$1" in -f) ParaFormat="$2"; shift 2;; -s) ParaSetting="$2"; shift 2;; --) shift;; *) if [ -z $1 ]; then break; elif [ -z $ParaSrc ]; then ParaSrc=$1; elif [ -z $ParaDst ]; then ParaDst=$1; else echo "Invalid argument: $1" >&2; printUsage exit 1; fi shift;; esacdoneif [ -z $ParaSrc ]; then echo "Invalid arguments." >&2; printUsage >&2; exit 1;fiecho "input : $ParaSrc"echo "output : $ParaSrc"echo "format : $ParaFormat"echo "setting : $ParaSetting"
- 【Bash脚本】处理命令行入参
- Bash命令行处理[详解]
- 详解Bash命令行处理
- 详解Bash命令行处理
- 详解Bash命令行处理
- 详解Bash命令行处理
- 详解Bash命令行处理
- 详解Bash命令行处理
- Bash Shell 命令行处理
- bash脚本字符串处理
- Bash下命令行处理方式
- 《学习bash》笔记--命令行处理
- Bash脚本之命令行参数$@和$*
- bash shell脚本处理传参,getopts的使用
- Bash命令行处理[详解]zz fromLinuxSir.Org
- Bash命令行处理[详解]——转贴
- Bash命令行处理流程详解(zz)
- Bash Shell 命令行 选项/参数处理
- C类型转换问题
- POJ2524(并查集)
- loner_li C#接口的定义及实现
- 创建型模式(Creational Pattern) 抽象工厂abstractfactory 建造者模式 buider 工厂方法模式 FactoryMethod 原型 prototype
- 魔咒词典 字典树 hash map
- 【Bash脚本】处理命令行入参
- 从零开始学C++之运算符重载(三):完善String类([]、 +、 += 运算符重载)、>>和<<运算符重载
- 七周七语言——Prolog(三)
- 手机信号强度
- Unity3D 物理引擎
- svn搭建
- ASIHTTPRequest系列(一):同步和异步请求
- gdi+设置图像的透明度
- UIToolBar使用示例