3 local short_options
=$1; shift;
4 local long_options
=$1; shift;
6 local unused_options
=""
10 if [[ ${1:0:2} = '--' ]]; then
11 if [[ -n ${1:2} ]]; then
13 for i
in ${long_options//,/ }; do
14 if [[ ${1:2} = ${i//:} ]]; then
19 if [[ -n $match ]]; then
22 [[ ${match} = ${1:2}: ]] && needsargument
=1
23 [[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument
=1
25 if (( ! needsargument
)); then
32 while [[ -n $2 && ${2:0:1} != "-" ]]; do
38 printf "@SCRIPTNAME@: $(gettext "option
%s requires an argument
\n")" "'$1'" >&2
43 echo "@SCRIPTNAME@: $(gettext "unrecognized option
") '$1'" >&2
50 elif [[ ${1:0:1} = '-' ]]; then
51 for ((i
=1; i
<${#1}; i
++)); do
52 if [[ $short_options =~
${1:i:1} ]]; then
55 [[ $short_options =~
${1:i:1}: && ! $short_options =~
${1:i:1}:: ]] && needsargument
=1
56 [[ $short_options =~
${1:i:1}:: && \
57 ( -n ${1:$i+1} ||
( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument
=1
59 if (( ! needsargument
)); then
60 printf ' -%s' "${1:i:1}"
62 if [[ -n ${1:$i+1} ]]; then
63 printf ' -%s ' "${1:i:1}"
64 printf "'%q" "${1:$i+1}"
65 while [[ -n $2 && ${2:0:1} != "-" ]]; do
72 printf ' -%s ' "${1:i:1}"
75 while [[ -n $2 && ${2:0:1} != "-" ]]; do
82 printf "@SCRIPTNAME@: $(gettext "option
%s requires an argument
\n")" "'-${1:i:1}'" >&2
89 echo "@SCRIPTNAME@: $(gettext "unrecognized option
") '-${1:i:1}'" >&2
94 unused_options
="${unused_options} '$1'"
100 [[ $unused_options ]] && printf ' %s' "${unused_options[@]}"
101 [[ $1 ]] && printf " '%s'" "$@"