Shell 摘抄:growpart中的参数处理

下面这段代码中,变量cur表示这次循环所要处理的参数。如果没有触发前面的选项开关,第一个参数会被赋值给$DISK,第二个参数会赋值给$PART
强无敌!~

while [ $# -ne 0 ]; do
        cur=${1}
        next=${2}
        case "$cur" in
                -h|--help)
                        Usage
                        exit 0
                        ;;
                --fudge)
                        FUDGE=${next}
                        shift
                        ;;
                -N|--dry-run)
                        DRY_RUN=1
                        ;;
                -u|--update|--update=*)
                        if [ "${cur#--update=}" != "$cur" ]; then
                                next="${cur#--update=}"
                        else
                                shift
                        fi
                        case "$next" in
                                off|auto|force|on) pt_update=$next;;
                                *) fail "unknown --update option: $next";;
                        esac
                        ;;
                -v|--verbose)
                        VERBOSITY=$(($VERBOSITY+1))
                        ;;
                --)
                        shift
                        break
                        ;;
                -*)
                        fail "unknown option ${cur}"
                        ;;
                *)
                        if [ -z "${DISK}" ]; then
                                DISK=${cur}
                        else
                                [ -z "${PART}" ] || fail "confused by arg ${cur}"
                                PART=${cur}
                        fi
                        ;;
        esac
        shift
done


posted @ 2023-01-30 11:50  武平宁  阅读(46)  评论(0)    收藏  举报