编程小贴士

给你的编程提供小点子


Bash 数组使用

在Bash中使用数组可以用

declare -a myArray

来定义,但是不是必须的,当你按照数组的方式对一个变量赋值的时候,它就成了数组。
数组可以直接赋值给另外一个变量,比如你可以用

PARAM=($@)
OTHER_COPY=(${PARAM[@]})

来拷贝命令行上的参数。
数组的下标从0开始,和C/Java中一样,比如打印数组中的第一个元素

echo ${PARAM[0]}

打印整个数组

echo ${PARAM[@]}

如果不加 [@] 则只能得到第一个元素,有点像C中的数组
而数组的长度可以用以下方法获得

echo ${#PARAM[@]}
echo ${#PARAM[*]}

获取数组的一部分,可以使用

PART=(${PARAM[@]:start:end})

若不加 :end 则取到数组结尾

65 Responses to “ Bash 数组使用 ”

  1. 大岩不灿说道:

    数组的遍历:
    for $item (${PARAM[@]}); do
    echo $item;
    done;

  2. 大岩不灿说道:

    数组的遍历:
    for ((i=0; i<${#PARAM[@]};i++)) do echo ${PARAM[i]}; done;

  3. best pron说道:

    JIipfb that I ave really enjoyed surfing around your blog posts.

  4. chocopie说道:

    WJP1YQ That will be the end of this article. Here you

  5. Smokers Lungs说道:

    Im obliged for the article.Really looking forward to read more. Want more.

  6. You have made some decent points there. I looked on the net to learn more about the issue and found most people will go along with your views on this web site.

  7. Looking forward to reading more. Great blog post.Really looking forward to read more. Want more.

  8. Very good information. Lucky me I ran across your site by chance (stumbleupon). I have book-marked it for later!

  9. Thanks for the sen Powered by Discuz

  10. Thanks so much for the blog article.Really thank you! Will read on

  11. Your style is unique compared to other folks I ave read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this web site.

  12. PhD Green Card说道:

    Your means of telling all in this article is really nice, all be capable of without difficulty know it, Thanks a lot.

  13. Nwokolo Collins说道:

    While checking out DIGG today I noticed this

  14. try this说道:

    Im thankful for the article post.Really thank you! Awesome.

  15. Thanks for sharing, this is a fantastic blog. Will read on

  16. Really enjoyed this blog.Thanks Again. Keep writing.

  17. Nice blog right here! Also your website loads up very fast! What web host are you the use of? Can I get your affiliate hyperlink for your host? I desire my website loaded up as fast as yours lol

  18. Thank you, I ave just been looking for information about this subject for ages and yours is the greatest I ave discovered till now. But, what about the conclusion? Are you sure about the source?

  19. Some genuinely prime articles on this web site , saved to favorites.

  20. adidas nmd说道:

    I simply wanted to post a simple message to be able to appreciate you for those amazing recommendations you are giving at this website. My time-consuming internet lookup has now been paid with good points to write about with my companions. I ‘d assert that we site visitors actually are definitely endowed to exist in a fine network with so many outstanding people with useful points. I feel extremely fortunate to have seen your entire webpage and look forward to plenty of more entertaining times reading here. Thanks a lot once again for a lot of things.

  21. This very blog is without a doubt entertaining and amusing. I have chosen many useful things out of this amazing blog. I ad love to go back again soon. Thanks!

  22. share说道:

    Nice Site , guys! Rewarding Articles aswell. Right into my social bookmarks

  23. This is a really good tip especially to those new to the blogosphere. Brief but very precise information Appreciate your sharing this one. A must read post!

  24. Successful tips说道:

    Really enjoyed this article post.Much thanks again. Really Great.

  25. Hosting说道:

    Thanks-a-mundo for the blog article.Really looking forward to read more. Really Great.

  26. Crochet说道:

    Interesting website, i read it but i still have a few questions. shoot me an email and we will talk more becasue i may have an interesting idea for you.

  27. white shoes说道:

    Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your site is great, let alone the content!. Thanks For Your article about sex.

  28. I used to be suggested this blog via my cousin. I am no longer sure whether this post is written by him as no one else realize such detailed about my trouble. You are wonderful! Thanks!

  29. Waec expo说道:

    Thankyou for this marvelous post, I am glad I detected this website on yahoo.

  30. Waec exam说道:

    I wished to compose you one particular extremely little remark to finally say thanks when far more over the

  31. agen sbobet说道:

    That is very fascinating, You are an overly professional blogger.

  32. Spot on with this write-up, I honestly think this web site needs much more attention. I all probably be returning to see more, thanks for the information!

  33. Wow! I cant think I have found your blog. Extremely helpful info.

  34. pretty beneficial material, overall I believe this is worthy of a bookmark, thanks

  35. Open heaven说道:

    pretty handy material, overall I feel this is worth a bookmark, thanks

  36. scary maze说道:

    Vu que nous voulons que votre bien, nous offrons la premiere communication

  37. wonderful issues altogether, you simply gained a logo new reader. What might you recommend in regards to your submit that you made some days in the past? Any sure?

  38. ventas说道:

    Im obliged for the blog.Really thank you! Awesome.

  39. That is a good tip especially to those fresh to the blogosphere. Short but very precise information Many thanks for sharing this one. A must read article!

  40. junior说道:

    This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your wonderful post. Also, I have shared your web site in my social networks!

  41. Judi Tembak Ikan说道:

    Say, you got a nice blog.Really looking forward to read more. Want more.

  42. to read more说道:

    I truly appreciate this blog article.Really looking forward to read more. Keep writing.

  43. that would be ok. I am definitely enjoying your blog and

  44. Perfect work you have done, this site is really cool with good info.

  45. Very good article.Really looking forward to read more. Will read on

  46. Really appreciate you sharing this article.Really thank you! Much obliged.

  47. One of the hair coconut oil hair growth construction and follicles.

  48. this website说道:

    that may be the finish of this write-up. Here you

  49. ndu说道:

    Really appreciate you sharing this blog post.Really thank you! Cool.

  50. Informative and precise Its difficult to find informative and precise information but here I found

  51. garage door说道:

    Your style is so unique compared to other people I ave read stuff from. I appreciate you for posting when you have the opportunity, Guess I will just book mark this page.

  52. classified说道:

    You produce a strong financially viable decision whenever you decide to purchase a motor vehicle with a

  53. wonderful issues altogether, you simply gained a new reader. What would you recommend about your publish that you made some days in the past? Any sure?

  54. Your writing is very useful, thank you very much.

  55. ballinaadvocate说道:

    Major thankies for the post.Much thanks again. Much obliged.

  56. visit说道:

    Really informative blog post.Really thank you! Keep writing.

  57. Daine说道:

    Some really nice stuff on this internet site , I love it.

  58. You have brought up a very excellent details , regards for the post.

  59. I was suggested this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are wonderful! Thanks!

  60. It as really a nice and helpful piece of info. I am glad that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing.

  61. Thank you for this entry. Looking forward to next one.

  62. Some genuinely choice articles on this website , saved to bookmarks.

  63. Informative article, exactly what I wanted to find.

  64. Incredibly Interesting Blog site! Thank you Just for this Website!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>