我怎样才能解析长篇论点的壳呢? [英] How can I parse long-form arguments in shell?
本文介绍了我怎样才能解析长篇论点的壳呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到的一切使用 getopt的
或略票友 getopts的
只支持单字符选项(例如, -h
而不是 - 帮助
)。我想要做的花式长选项。
Everything I see uses getopt
or the slightly-fancier getopts
which only supports one-character options (e.g., -h
but not --help
). I want to do fancy long options.
推荐答案
我已经做了类似的这个:
_setArgs(){
while [ "$1" != "" ]; do
case $1 in
"-c" | "--configFile")
shift
configFile=$1
;;
"-f" | "--forceUpdate")
forceUpdate=true
;;
"-r" | "--forceRetry")
forceRetry=true
;;
esac
shift
done
}
如你所见,这既支持单字符和更长的选项很好。它允许与每个参数相关联的值,如的情况下 - CONFIGFILE
。这也是很容易扩展,没有人为限制,以什么方式可以配置等。
As you can see, this supports both the single-character and the longer options nicely. It allows for values to be associated with each argument, as in the case of --configFile
. It's also quite extensible, with no artificial limitations as to what options can be configured, etc.
这篇关于我怎样才能解析长篇论点的壳呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文