CWYAlpha

Just another WordPress.com site

Thought this was cool: Shell编程中的数组定义、遍历

leave a comment »


数组定义:

arr=(1 2 3 4 5) # 注意是用空格分开,不是逗号!!

遍历(For循环法):

for var in ${ arr[@] };
do
    echo $var
done

遍历(While循环法):

i=0
while [ $i -lt ${ #array[@] } ]
do
    echo ${ array[$i] }
    let i++
done

from 四号程序员: http://www.coder4.com/archives/3853

Written by cwyalpha

四月 11, 2013 在 3:23 上午

发表在 Uncategorized

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: