BASH Shell learning-array

Source: Internet
Author: User
Definition Method

Subscript array direct assignment
#! /Bin/basharr [0] = "one" arr [1] = "two" arr [2] = "three" for num in $ {arr [*]} doecho $ numdone

Sequential assignment of parentheses

Arr = ("four" "five" "six") for num in $ {arr [*]} doecho $ numdon

Execution result join array premise: associated array requires syntax declaration, refer to: http://blog.csdn.net/zinss26914/article/details/8675058

Declare-A array_name

Assignment

#! /Bin/bashdeclare-A arrarr ["name"] = "wangzhengyi" arr ["sex"] = "boy" arr ["Age"] = "25" for Param in $ {arr [*]} doecho $ paramdone

Run the. array length and read array length command.

Use $ {# array name [* or @]} to obtain the array length.

Example array value reading command

Use $ {subscript array name [subscript]} or $ {join array [Key]}

Note: If the subscript is * or @, you can obtain the sample array key reading command for the entire array.

$ {! Array name [* or @]}

After the example, keep learning and summarize it. In the future, some shell knowledge will be updated frequently, which is commonly used for O & M!

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.