IE是否經(jīng)常中毒?推薦您
Bash中還可以使用數組變量,其賦值有兩種:
(1) name = (value1 ... valuen) 此時(shí)下標從0開(kāi)始
(2) name[index] = value
數組下標的范圍沒(méi)有任何限制,同時(shí)也不必使用連續的分量.
--------------------------------------------------------------------------------
$ A=(a b c def)
==================================================
$ echo ${A[@]} //取全部元素
a b c def
=================================================
$ echo ${A[0]} //取第一個(gè)元素
a
=================================================
//取得數組元素的個(gè)數
$ echo ${#A[@]}
4
$ echo ${#A }
4
$ echo ${#A[3]} //取得元素3的長(cháng)度
$
==================================================
$ A[3]=yaoshuyin //將第三個(gè)元素重新賦值
$ echo ${A[@]}
a b c yaoshuyin
==================================================
//清除變量
$ unset A
$ echo ${A[@]}
$
==================================================
//清空變量,即將值變?yōu)榭?div style="height:15px;">
$ A=
$ echo ${A[@]}
$
==================================================
A=B
B=C
unset $A 事實(shí)上所取消的變量是 B 而不是 A
=======================示例 while循環(huán)========================
#建立數組
arrSource=("arrJobs.php" "arrSubHangye.php" "arrFirst.php" )
arrDest=("buildhr" \
"buildtrain/htdocs" \
"bankhr" \
"healthr" \
"elehr" \
)
#取數組無(wú)元素個(gè)數
lenArrSource=${#arrSource
}
lenArrDest=${#arrDest
}
#循環(huán)列出數組元素
i=0
while [ $i -lt $lenArrSource ]
do
echo ${arrSource[$i]}
let i++
done
i=0
while [ $i -lt $lenArrDest ]
do
echo ${arrDest[$i]}
let i++
done
=======================示例: for循環(huán)===============================
#源文件
arrSource=("/home/800hr/htdocs/login_jump.php")
#目標網(wǎng)站
arrDest=(ithr elehr buildhr bankhr healthr ctvhr chenhr mechr clothr cneduhr 56hr tourhr foodhr greenhr cnlawhr waimaohr)
for outer in ${arrSource
} #${arrSource
} 是數組中的所有元素
do
for inner in ${arrDest
}
do
echo "ln -s $outer /home/${inner}/campus/"
done
done