标签:编写 value getopts idc pts 参考 top ref host
在编写 shell 脚本中,经常要处理一些输入参数,在使用过程中发现 getopts 更加方便,能够很好的处理用户输入的参数和参数值
#!/bin/bash while getopts :ab:c opt do case "$opt" in a) echo "Found the -a option" ;; b) echo "Found the -b option, with value $OPTARG";; c) echo "Found the -c option" ;; *) echo "Unknown option: $opt";; esac
[root@localhost ~]# sh 1.sh -a Found the -a option [root@localhost ~]# sh 1.sh -c Found the -c option [root@localhost ~]# sh 1.sh -b 123 Found the -b option, with value 123
参考1:http://www.jxbh.cn/article/2097.html
参考2:http://www.linuxidc.com/Linux/2016-06/132102.htm
标签:编写 value getopts idc pts 参考 top ref host
原文地址:http://www.cnblogs.com/pzk7788/p/7618495.html