Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/docs/ksh/functions/getopt.txt
1798 views
1
function getopt
2
{
3
typeset c optstring=$1 options= sep=
4
shift
5
while getopts $optstring c
6
do case $c in
7
[:?])
8
exit 2
9
;;
10
*)
11
options="$options$sep-$c"
12
sep=' '
13
if [[ $optstring == *$c:* ]]
14
then options=" $options $OPTARG"
15
fi
16
#then print -rn -- " -$c" "$OPTARG"
17
#else print -rn -- " -$c"
18
;;
19
esac
20
done
21
print -rn -- "$options"
22
if [[ ${@:$OPTIND-1} != -- ]]
23
then print -rn -- " --"
24
fi
25
if [[ -n ${@:$OPTIND} ]]
26
then print -r -- " ${@:$OPTIND}"
27
fi
28
}
29
30