[shell]shell脚本传入不固定参数的写法,如--help等
最近在调试一个wifi模块,需要传一些不固定的参数,一下一个参数解析的函数可以搞定这个事情,里面内容好多部分是从一个example中剽窃而来(窃喜)
#!/bin/bash
# writen by aaron.gao at 2017.06. arg_ssid="ssid-test"
arg_passphrase="passphrase-test"
arg_ifip="192.168.4.1"
arg_stop=""
arg_start=""
arg_help="" print_help() {
cat <<EOF
use $program --ssid=<ssid> --ssid=<ssid> - where <ssid> is the name of the AP advertised with the beacon frames. (default:$arg_ssid)
--passphrase=<passphrase> - where <passphrase> is the password of AP (default:$arg_passphrase) --stop - stop accesspoint
--start - also start accesspoint
--help - prints help screen EOF
} parse_arguments() {
local helperKey="";
local helperValue="";
local current=""; while [ "$1" != "" ]; do
current=$;
helperKey=${current#*--};
helperKey=${helperKey%%=*};
helperKey=$(echo "$helperKey" | tr '-' '_');
helperValue=${current#*=};
if [ "$helperValue" == "$current" ]; then
helperValue="";
fi
#echo "eval arg_$helperKey=\"$helperValue\""; eval "arg_$helperKey=\"$helperValue\"";
shift
done
} parse_arguments ${@}; if [ "$arg_help" != "" ]; then
print_help;
exit ;
fi if [ "$arg_stop" == "" ]; then
kill $(pidof -o %PPID -x $(basename $))
./uaputl.exe bss_stop ifconfig uap0 down;
exit
fi ifconfig uap0 up; # echo "set ssid and passwd"
./uaputl.exe sys_cfg_ssid $arg_ssid
./uaputl.exe sys_cfg_auth
./uaputl.exe sys_cfg_protocol #sets WPA2 protocol
./uaputl.exe sys_cfg_wpa_passphrase $arg_passphrase
./uaputl.exe sys_cfg_cipher #PAIRWISE_CIPHER:AES CCMP GROUP_CIPHER:AES CCMP # echo "set RF params"
./uaputl.exe sys_cfg_channel #Set AP primary radio channel to , and
# secondary channel is below.
./uaputl.exe sys_cfg_2040_coex #enable / BSS coexistence Configuration
./uaputl.exe sys_cfg_11n 0x116e 0xff
./uaputl.exe sys_cfg_rates 0xc 0x12 0x18 0x24 0x30 0x48 0x60 0x6c # echo "set regulation domain"
./uaputl.exe sys_cfg_80211d state country DE if [ "$arg_start" == "" ]; then
sleep ;
./uaputl.exe bss_start ifconfig uap0 "$arg_ifip" fi exit ;
[shell]shell脚本传入不固定参数的写法,如--help等的更多相关文章
- linux shell判断脚本执行时传入了多少个参数,判断脚本参数个数,参数数量
		需求描述: 在写shell脚本的时候,会有这样的需求,脚本在执行的过程中是需要传入参数的,如果没有参数传递给脚本, 就会给出相应的脚本使用方法或者例子,告知,脚本后面应该加什么样的参数.所以呢,这里要 ... 
- Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载
		Shell脚本中判断输入参数个数的方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了Shell脚本中判断输入参数个数的方法,使用内置变量$#即可实现判断输入了多少个参数 ... 
- Shell脚本编写3---Shell 传递参数
		我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 执行脚本,查看输出结果: 另外 ... 
- awk如何区分shell脚本传进来的参数和自身的参数?awk如何获取shell脚本传进来的参数;awk中如何执行shell命令
		问题:对于shell脚本,$0表示脚本本身,$1表示脚本的第一个参数,$2……依次类推:对于awk,$1表示分割后的第一个字段,$2……依次类推.那么对于shell脚本中的awk如何区分两者呢? 答案 ... 
- Shell编程 | 脚本参数与交互及常见问题
		在执行一个脚本程序时,会经常需要向脚本传递一些参数,并根据输入的参数值生成相应的数据或执行特定的逻辑. 向脚本传递参数 执行Shell脚本时可以带有参数,在Shell脚本中有变量与之对应进行引用.这类 ... 
- Shell最多可以输入多少个参数?
		在脚本编写过程中,通常会涉及到参数的输入.譬如,sh 1.sh 10 20,在执行1.sh这个脚本中,10即为第一个参数,20即为第二个参数.有时,就会有这个疑惑,即shell脚本最多可以支持多少个变 ... 
- Shell与脚本
		shell是Linux操作系统的用户接口,我们经常需要编写脚本让操作系统自动执行一系列指令的需求,本文将简单介绍开发shell脚本的所需的语言特性. shell脚本是指令序列,其指令可以直接在终端中执 ... 
- 使用shell解析脚本依赖关系,并自动补数
		将脚本依赖关系放到表中 使用shell解析脚本依赖关系,递归的计算各个脚本. #!/bin/bash # dm 补数 basepath=$(cd ``; pwd) cd $basepath sourc ... 
- shell及脚本4——shell script
		一.格式 1.1 开头 必须以 "# !/bin/bash" 开头,告诉系统这是一个bash shell脚本.注意#与!中间有空格. 二.语法 2.1 数值运算 可以用decla ... 
随机推荐
- C# 生成 DataMatrix 格式的二维码
			该文主要是利用OnBarcode.dll 生成 DataMatrix 格式的二维码的一些简单方法和操作技巧.关于QrBarcode的二维码比较常见和简单,网上有很多资源. 1.附件为dll 2.利用上 ... 
- MyBatis JdbcType 与Oracle、MySql数据类型对应关系详解
			本文转自:http://blog.csdn.net/loongshawn/article/details/50496460 1. Mybatis JdbcType与Oracle.MySql数据类型对应 ... 
- HDUOJ-----(1329)Calling Extraterrestrial Intelligence Again
			Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ... 
- Android中的Service使用
			Service的生命周期 (适用于2.1及以上) 1. 被startService的无论是否有任何活动绑定到该Service,都在后台运行.onCreate(若需要) -> onStart(in ... 
- Python学习笔记012——装饰器
			1 装饰器 1.1装饰器定义 在代码运行期间动态增加功能的方式,称之为“装饰器”(Decorator). 1.2 装饰器分类 装饰器:函数装饰器,类装饰器,函数的装饰器,类的装饰器 装饰器:函数装饰函 ... 
- go 学习笔记(2) --变量、常量、iota、数组
			参考网址:https://gobyexample.com 变量 Go中使用全新的关键字var来声明变量.var我们并不陌生,在Javascript 和C#中均有出现.不同的是Go和C#中变量属于强类型 ... 
- Linux进程概述
			一.介绍 当linux系统中的一个进程运行起来的时候,总是要访问系统的资源,访问文件或者向其他的进程发送信号.系统是否允许其进行这些操作?系统是根据什么来判断该进程的权限?这些问题是和进程信任状(pr ... 
- <<Python基础教程>>学习笔记 | 第10章 | 充电时刻
			第10章 | 充电时刻 本章主要介绍模块及其工作机制 ------ 模块 >>> import math >>> math.sin(0) 0.0 模块是程序 一个简 ... 
- SIPp常用脚本之二:UAS
			看名字就能猜出来,这是作为SIP消息服务端的存在,启动uas,等着接受SIP消息并且给出响应. 一.uas.xml <?xml version="2.0" encoding= ... 
- 项目打成jar包
			distributionManagement 为发布到本地参考的地址 repository 设置从本地maven库拉取jar包 <project xmlns:xsi="http://w ... 
