最近在调试一个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等的更多相关文章

  1. linux shell判断脚本执行时传入了多少个参数,判断脚本参数个数,参数数量

    需求描述: 在写shell脚本的时候,会有这样的需求,脚本在执行的过程中是需要传入参数的,如果没有参数传递给脚本, 就会给出相应的脚本使用方法或者例子,告知,脚本后面应该加什么样的参数.所以呢,这里要 ...

  2. Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载

    Shell脚本中判断输入参数个数的方法 投稿:junjie 字体:[增加 减小] 类型:转载   这篇文章主要介绍了Shell脚本中判断输入参数个数的方法,使用内置变量$#即可实现判断输入了多少个参数 ...

  3. Shell脚本编写3---Shell 传递参数

    我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 执行脚本,查看输出结果: 另外 ...

  4. awk如何区分shell脚本传进来的参数和自身的参数?awk如何获取shell脚本传进来的参数;awk中如何执行shell命令

    问题:对于shell脚本,$0表示脚本本身,$1表示脚本的第一个参数,$2……依次类推:对于awk,$1表示分割后的第一个字段,$2……依次类推.那么对于shell脚本中的awk如何区分两者呢? 答案 ...

  5. Shell编程 | 脚本参数与交互及常见问题

    在执行一个脚本程序时,会经常需要向脚本传递一些参数,并根据输入的参数值生成相应的数据或执行特定的逻辑. 向脚本传递参数 执行Shell脚本时可以带有参数,在Shell脚本中有变量与之对应进行引用.这类 ...

  6. Shell最多可以输入多少个参数?

    在脚本编写过程中,通常会涉及到参数的输入.譬如,sh 1.sh 10 20,在执行1.sh这个脚本中,10即为第一个参数,20即为第二个参数.有时,就会有这个疑惑,即shell脚本最多可以支持多少个变 ...

  7. Shell与脚本

    shell是Linux操作系统的用户接口,我们经常需要编写脚本让操作系统自动执行一系列指令的需求,本文将简单介绍开发shell脚本的所需的语言特性. shell脚本是指令序列,其指令可以直接在终端中执 ...

  8. 使用shell解析脚本依赖关系,并自动补数

    将脚本依赖关系放到表中 使用shell解析脚本依赖关系,递归的计算各个脚本. #!/bin/bash # dm 补数 basepath=$(cd ``; pwd) cd $basepath sourc ...

  9. shell及脚本4——shell script

    一.格式 1.1 开头 必须以 "# !/bin/bash"  开头,告诉系统这是一个bash shell脚本.注意#与!中间有空格. 二.语法 2.1 数值运算 可以用decla ...

随机推荐

  1. git版本库管理介绍,撤销git pull操作

    Git是分布式版本控制系统,GitHub 是最大的 Git 版本库托管商,是成千上万的开发者和项目能够合作进行的中心. 大部分 Git 版本库都托管在 GitHub,很多开源项目使用 GitHub 实 ...

  2. define() vs const 该如何选择?

    使用 define(),除非考虑到可读性.类常量.或关注微优化 1.在 PHP 中是使用 define() 函数来定义常量,PHP 5.3.0 以后,PHP 中也能够使用 const 关键字来声明常量 ...

  3. C#编写的 8种初级+高级排序方法(转)

    摘自:http://blog.csdn.net/mevin/article/details/6714520 程序代码: view plaincopy to clipboard using System ...

  4. html5中的FileReader对象

    表单中有图片选项,选中图片文件之后要求可以预览.这个功能很多控件都封装好了,但是它们的底层都是FileReader对象. FileReader对象提供了丰富的功能,包括以二进制.以文本方式读取文件内容 ...

  5. pandas 的数据结构Series与DataFrame

    pandas中有两个主要的数据结构:Series和DataFrame. [Series] Series是一个一维的类似的数组对象,它包含一个数组数据(任何numpy数据类型)和一个与数组关联的索引. ...

  6. 常用JS技巧[转]

    作者:72妃 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); even ...

  7. configure: error: newly created file is older than distributed files!

    在linux下安装软件包的时候,有时候提示 configure: error: newly created file is older than distributed files!Check you ...

  8. Python学习笔记015——汉字编码

    1 字符串的编码(encode)格式 GB2312   GBK   GB18030  UTF-8  ASCII 其中常用的编码格式有 国标系列:GB18030(GBK(GB2312)) (window ...

  9. PLSQL_统计信息系列06_统计信息的历史和日志

    20150506 Created By BaoXinjian

  10. ASP.NET Helper