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