最近在调试一个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. 原创:【微信小程序】发送消息模板教程(后台以PHP示例)

    1.本教程对外开放,未经博主同意,禁止转载. 2.准备材料:1)公众号|小程序,添加选择的模板消息,2)在设置>开发设置页面,开通消息模板功能:如: 3.因为调用微信发送模板的接口是:https ...

  2. HDUOJ-----1166敌兵布阵

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. BasicAuth和OAuth

    参考资料 百度百科BasicAuth 维基百科OAuth BasicAuth基本授权 BasicAuth又叫HttpAuth,它非常简单.例如你访问一个页面时,会弹出用户名密码框 它的优点是:简单,只 ...

  4. 【LeetCode】31. Next Permutation (2 solutions)

    Next Permutation Implement next permutation, which rearranges numbers into the lexicographically nex ...

  5. Android oncreate onupgrade什么时候被调用

    在学习Android数据库SQLite之前,必须意识到这一点,目前在Android系统中集成的是SQLite3 版本,SQLite是一个开源的嵌入式数据库,他支持NULL.INTEGER.REAL.T ...

  6. Sql 列转行 三种方法对比

    合并列值   --******************************************************************************************* ...

  7. Model实例化类属性与值使用反射拼接成SQL语句

    public string GetInsertSqlByModel(Object o) { StringBuilder sbStart = new StringBuilder(); StringBui ...

  8. spring 读取配置文件

    spring读取dubbo xml文件,在本项目内可以调用正常,一旦把改项目打成jar包,供其他项目调用,就会提示找不到配置文件 ClassPathXmlApplicationContext cont ...

  9. matlab直方图均衡

    clear all; i=imread('cameraman.tif'); figure; subplot(2,2,1); imshow(i); title('原始图像'); subplot(2,2, ...

  10. ubuntu为python处理图片安装图片数据增强库imgaug

    1 依赖Required dependencies: six numpy scipy scikit-image (pip install -U scikit-image) OpenCV (i.e. c ...