脚本获取输入参数shell之getopt

前端之家收集整理的这篇文章主要介绍了脚本获取输入参数shell之getopt前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

从 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 $* 原文链接:https://www.f2er.com/bash/391752.html

猜你在找的Bash相关文章