In which status the `Internal error!` invoked?

感情迁移 提交于 2020-01-15 09:42:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!