shell操作数组
shell操作数组
shell操作数组
Shell代码
./test.sh "100,200 300,400 500,600" hhhh
www.2cto.com
说明:参数分隔符默认是空格,所以数组参数用双引号扩上,
Shell代码
dd=`date +%Y%m%d_%H%M%S`
echo "start datetime ${dd}"
arrayListParam=$1
printName=$2
arrayList=($arrayListParam)
echo "length = ${#arrayList[@]}"
i=0
while [ $i -lt ${#arrayList[@]} ];do
firstsplit=`echo "${arrayList[$i]}" | cut -d "," -f1`
secondsplit=`echo "${arrayList[$i]}" | cut -d "," -f2`
echo "${printName}_${firstsplit}:${secondsplit}"
let i=i+1
done
dd=`date +%Y%m%d_%H%M%S`
echo "end datetime ${dd}"
显示结果:
Shell代码
start datetime 20130305_181428
length = 3
hhhh_100:200
hhhh_300:400
hhhh_500:600
end datetime 20130305_181428
评论暂时关闭