Linux plain arrays and associative arrays

Source: Internet
Author: User

Arrays: You use an index to store multiple data as a collection.

Normal array: The index of an array can only use integers

Associative arrays: Array indexes can use integers and strings (associative arrays are supported for versions above bash4.0)

Arrays are often used in interactions with loops or other judgments to make a higher sense.

Definition of an ordinary array

Array1= (a AB 3a)

The index of the array from 0 to the starting index

echo ${array1[0]} output: A

echo ${array1[2]} output: 12

Arrays can also be defined as

arry[0]= "Test0"

arry[1]= "Test1"

arry[2]= "Test2"

Print the values in the array at once

echo ${arry[*]} or echo ${arry[@]}

Output: Test0 test1 test2

Print all indexes of an array

Echo ${!arry[*]}

Output: 0 1 2

Print the total number of array values

echo ${#arry [*]}

Output: 3

Associative array definitions

First, declare that this array3 is an associative array

Declare-a arr

Associative array Assignment

index = value

Arr= ([App]=a [n-11]=b [110]=c]

can also

Array3[aa]=var1

Array3[a10]=var2

Print the values in the array at once

Echo ${array3[*]}

Print all indexes of an array

Echo ${!array3[*]}



This article is from the "Tiandaochouqin" blog, make sure to keep this source http://xiang99.blog.51cto.com/3583449/1413762

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.