Nine arrays in the shell

Source: Internet
Author: User

Array: A variable that stores a set of data and is able to manipulate one of the data in this set of data individually.

Types of arrays: one-dimensional arrays, two-dimensional arrays, multidimensional arrays

Types of variables

The default value of an untyped variable in the shell is automatically converted to an integer when it is used as text in a numeric operation.

Defining variable Types

declare: Force set type properties

syntax:declare option variable name

option    Comment -i    Force integer -A    defines an array -X    set to global variable/ environment variable -R    set to read-only

-I: Define variables as numeric types

[Email protected] ~]#declare-i x= ~]# declare-i y=3~]# declare-i c= $x *  ~]# echo $c

-A : Define variable array type

[email protected] ~]# declare-~]# declare-a |  -a tea='()'~]#tea= ~]# declare-a |  -a tea='([0]= "PLJ" [1]= "HPG" [2]= "ZHF" [3]= "Zzg")'

defines or assigns an array of values

Method 1, Overall assignment

format    Example array name = (value 1 value 2 ....) Value N)    svrs= (www ftp mail club)

Method 2: Assign a value to a single element

format    Example array name [subscript]= value; subscript starting    from 0 fqdns[0]=www.tarena.com

Output array elements

    Format gets a single array element    ${array name [subscript]} gets all array elements    ${array name [@]} Gets the number of array elements    ${#数组名 [@]} get successive array elements    ${array name [@]}: Start subscript: The number of elements gets the length of an element of an    array ${#数组名 [subscript]} to intercept part of the value of an element    ${#数组名 [subscript]: Start subscript: Characters}

Special Reminders:

If an element subscript value has already been used by an existing element, the value of the existing element is modified
Adds a new element to an array if the element subscript value is not used by an existing element
If you assign a value to an array, the list of elements is empty, and all elements in the array are deleted
If you assign a value to an array, the element list enters a new value, and it is re-assigned to the array.

Nine arrays 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.