So I have the following script to sort command line options I got it from here:
optstring=h
unset options #deletes options
while(($#));
do
echo $item;
case $1 in
-[!-]?*) # caso a op??o seja do tipo -ab
for ((i=1; i < ${#1}; i++));do # Loop sobre cada caracter
c=${1:i:1}
options+=("-$c")
if [[ $optstring = *"$c:"* && ${1:i+1} ]];
then
options+=("${1:i+1}")
break
fi
done;;
#type --foo=bar
--*[^=*]) options+=("${1%%=*}") ;
echo "${options[@]}";;
#THIS ONE IS NOT WORKING IDK WHY
--?*=*) options+=("${1%%=*}" "${1#*=}") ;
echo "${options[@]}";;
# adds --endopts for --
--) options+=(--endopts)
echo "${options[@]}";;
*) options+=("$1")
echo "${options[@]}";;
esac
shift
done
And besides not working properly I feel that there is a better way to do this.
Can anyone point me in the right direction or at least tell me what I am doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…