0
誰可以幫助給出一個shell腳本示例來顯示$*
和[email protected]
之間的區別?
以下是我的腳本,但它無法分辨。任何人都可以舉一個好榜樣?
$ cat internalVar.sh
#!/bin/bash
# internalVar.sh var1 var2
echo "\$? = " $?
export IFS="_"
echo "\[email protected] = " [email protected] " == several parameters?"
j=1
for i in [email protected]
do
echo "var $j = $i"
j=$((j+1))
done
echo "\$* = " $* " == a single string"
j=1
for i in $*
do
echo "var $j = $i"
j=$((j+1))
done
echo "\$# = " $#
echo "\$0 = " $0
echo "\$$ = " $$
$ export IFS="c"
[$ ./internalVar.sh par1 "par meter 2" par3
$? = 0
[email protected] = par1 par meter 2 par3 == several parameters?
var 1 = par1
var 2 = par meter 2
var 3 = par3
$* = par1 par meter 2 par3 == a single string
var 1 = par1
var 2 = par meter 2
var 3 = par3
$# = 3
$0 = ./internalVar.sh
$$ = 4638
您的腳本無法區分它的差異,因爲它沒有使用適當的引號。如果沒有正確引用,那麼**就沒有區別(並且會有很多錯誤)。 –
@CharlesDuffy Duh,當然有重複。我一定以爲「這不是問'var = val',它一定是新的;) –
謝謝你們,我明白了。 –