问题
I have read some code on bash's getopt ,let me simplify what i have seen hrere.
bash sample on getopt containing Internal error!
docase(){
TEMP=`getopt -o ab: -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-a) echo "Option a" ; shift ;;
-b) echo "Option b, argument \`$2'" ; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ;;
esac
done
}
I have tried many status to invoke Internal error!
with docase g
,docase -g
,docase --g
,never happened.
In which status the Internal error!
invoked for the above code ?
Maybe it is better to delete *) echo "Internal error!" ;;
?
回答1:
docase(){
TEMP=`getopt -o ab: -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-a) echo "Option a" ; shift ;;
-b) echo "Option b, argument \`$2'" ; shift 2 ;;
--) shift ;;
*) echo "Internal error!" ;;
esac
done
}
To delete break in --) shift ; break ;;
invoke infinite Internal error!
.
docase(){
TEMP=`getopt -o ab: -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-a) echo "Option a" ; shift ;;
-b) echo "Option b, argument \`$2'" ; shift 2 ;;
--) shift ;;
*) echo "Internal error!" ;break;;
esac
done
}
To add a break in *) echo "Internal error!"
invoke Internal error!
only once.
来源:https://stackoverflow.com/questions/51742613/in-which-status-the-internal-error-invoked