Arrays in the Linux shell and traversal

Source: Internet
Author: User

Transferred from: http://www.linuxidc.com/Linux/2011-09/42929.htm

When using the shell under Linux, for convenience, an array is occasionally used. The way the array is declared is:

    1. array= (element1 element2 element3 .... elementn)

That is, wrapping the array elements directly with parentheses, and separating the elements of the array with spaces.

The data is read as follows

    1. #echo ${array[0]}
    2. #echo ${array[index]}

The traversal of the array is used for a fetch all:

    1. ${array[@]}

, the complete example is as follows:

      1. for  data in ${array[@]}  
      2. do   
      3.     echo ${data}  
      4. Done
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.