Files
cdesktop/docs/ksh/functions/getopt.txt
Jon Trulson 97ef0077f0 Squashed 'cde/programs/dtksh/ksh93/' content from commit b16c91f01
git-subtree-dir: cde/programs/dtksh/ksh93
git-subtree-split: b16c91f0120895eaae2618e821cac5b4eda27ac2
2022-08-27 13:53:17 -06:00

29 lines
488 B
Plaintext

function getopt
{
typeset c optstring=$1 options= sep=
shift
while getopts $optstring c
do case $c in
[:?])
exit 2
;;
*)
options="$options$sep-$c"
sep=' '
if [[ $optstring == *$c:* ]]
then options=" $options $OPTARG"
fi
#then print -rn -- " -$c" "$OPTARG"
#else print -rn -- " -$c"
;;
esac
done
print -rn -- "$options"
if [[ ${@:$OPTIND-1} != -- ]]
then print -rn -- " --"
fi
if [[ -n ${@:$OPTIND} ]]
then print -r -- " ${@:$OPTIND}"
fi
}