4

我知道getopts,但我必须每次都进行解析和错误处理。

有谁知道 Bash 是否存在用于解析命令参数的“库”或一组函数?

例如 Perl 有很多这样的东西。

4

2 回答 2

3

也许getoptx适合你。虽然我发现 getopts 真的很好而且顺便说一句。:如果你使用用户输入,你应该总是做一些错误处理;-)

于 2012-10-30T18:09:49.957 回答
1

bash-modules,“参数”模块。

例子:

#!/bin/bash
. import.sh log arguments

NAME="world"

parse_arguments "-n|--name)NAME;S" -- "$@" || {
  error "Cannot parse command line."
  exit 1
}

info "Hello, $NAME!"
于 2013-07-09T15:26:01.613 回答