1
將參數傳遞給函數時,我很難理解[email protected]
和$*
之間的區別。
這裏是例子:
function a {
echo "-$1-" "-$2-" "-$3-";
}
function b {
a "[email protected]"
}
function c {
a "$*"
}
如果電話:
$ b "hello world" "bye world" "xxx"
它打印:
-hello world- -bye world- -xxx-
如果電話:
$ c "hello world" "bye world" "xxx"
它打印:
$ c "hello world" "bye world" "xxx"
-hello world bye world xxx- -- --
發生了什麼事?我無法理解差異,出了什麼問題。
「$ @」與有參數一樣多的字符串; 「$ *」是單個字符串。這個問題有很多問題 - 我會很快找到。 –
謝謝@JonathanLeffler,這是一個很好的閱讀。 – bodacydo