加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

脚本获取输入参数shell之getopt

发布时间:2020-12-15 16:37:04 所属栏目:安全 来源:网络整理
导读:从 man getopt中拷贝出来,简单改了改,更方便看了 #!/bin/bash function mygetopt() { args=`getopt c:n:o:i: $*` if [ $? != 0 ] then echo 'Usage: ...' exit 2 fi set -- $args for i do case "$i" in -c) shift; conf_file=$1; shift;; -i) shift; in_f

从 man getopt中拷贝出来,简单改了改,更方便看了

#!/bin/bash function mygetopt() { args=`getopt c:n:o:i: $*` if [ $? != 0 ] then echo 'Usage: ...' exit 2 fi set -- $args for i do case "$i" in -c) shift; conf_file=$1; shift;; -i) shift; in_file=$1; shift;; -o) shift; out_file=$1; shift;; -n) shift; number=$1; shift;; --) shift; break;; esac done } function main() { mygetopt $* echo "conf_file: " $conf_file echo "in_file: " $in_file echo "out_file: " $out_file echo "number: " $number } main $*

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读