An array of special variable types in the shell

Source: Internet
Author: User
There are two types of data in the shell: one is a numeric type, the other is a string type , and although the shell itself is a weak type, it can be so distinguished.
If we need to store multiple values in a variable in the shell, we need a more convenient type array
Array in the shell is enclosed in parentheses each value is separated by a space to define an array
A= (1 2 3 4 5)
A= ("A" "B" "C" "D" "E")
A= (1 "A" 2 "B")
It's all possible.

The use of arrays
Get the length of the array: ${#a [*]} or ${#a [@]}
Get all the values in the array: ${a[*]} or ${a[@]}
Get the specified value in the array: ${a[digit]} #digit表示数字下标, that is, the position of each element of the array is counted from 0
Gets the value of the contiguous position in the array: ${a[*]:0:3} Here is a method using a string intercept ${var: Start position: Length}
Modify the value of an array a[subscript]= value
Iterating through an array with a For loop
For i in ${a[@]}; Do
echo I
Done
Delete a value in an array
unset a[Subscript]

An array of special variable types in the shell

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.