為什麼在這種情況下使用“shift”命令?

為什麼在這種情況下使用“shift”命令?

我正在重寫 debootstrap 以適合我和教育。為什麼在「functions」檔案中的互動程式碼中使用「shift」指令?沒有那麼多參數發送來使用“shift”,而且據我所知,函數參數只能在函數中存取。

例子:

error () {
# <error code> <name> <string> <args>
local err="$1"
local name="$2"
local fmt="$3"
shift; shift; shift
if [ "$USE_DEBIANINSTALLER_INTERACTION" ]; then
    (echo "E: $name"
    for x in "$@"; do echo "EA: $x"; done
    echo "EF: $fmt") >&4
else
    (printf "E: $fmt\n" "$@") >&4
fi
exit $err
}

答案1

這三個轉變從參數中刪除了錯誤代碼、名稱和字串,因此其餘參數可以方便地放入腳本第九行的循環中$@for

相關內容