In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Array concept
According to the production requirements, the data with some common characteristics are organized into a set to facilitate traversal, query and management, the array is a collection of variables, and the array in shell is equivalent to the list and dictionary of Python.
Ordinary array
1. The index number is a number, and the default starting index number is 02. This is equivalent to listing 3 in Python. There is no need to declare, just use
Associative array
1. The index format can be customized, and the associative array data is a collection of key values such as key and Value. Equivalent to a dictionary in python. 3. Must be declared first.
Sparse array:
The discontinuity of index numbers becomes a sparse array.
Array declaration:
Normal array: declare-an ARRAY_NAME
Associative array: declare-An ARRAY_NAME
View the data sets defined in the system declare-a
Array assignment
Assign only one element at a time
Assign all elements at once
Only assign values to specified elements
Interactive array
Data element reference
Reference array elements: ${ARRAY_ name [index]} reference array all elements ${ARRAY_NAME [*]} ${ARRAY_NAME [@]} length of data ${# ARRAY_NAME [*]} ${# ARRAY_NAME [@]} Delete elements in the array: cause the sparse format unset ARRAY [INDEX] to delete the entire array unset ARRAY
Example:
Array data processing
Syntax: ${ARRAY [@]: offset:number} n is the start and end position, m is the intercept length
Memory ideas:
Offset: the start offset of the element string from left to right is numbered 0, and the offset from right to element string is numbered-1
Offset: the element string offset number corresponds to the starting position in the Python string slice
When offset is positive, it is intercepted from left to right; if it is negative, it is intercepted from right to left.
Number: the length of the element string to be intercepted corresponds to the end position in the Python string slice.
When number is positive, it represents the intercept length, if it is negative, it represents the end position. When number is the end position, the interception does not include the m-bit.
Note: when using negative interception, negative numbers must be separated by a space from a colon.
When the instance 1:offset is positive, truncate from left to right: ${ARRAY [@]: N m}, n is the starting and ending position, m is the truncated length
From left to right, intercept the starting position is n, take m characters.
If the intercept length m is not specified, the nth bit is intercepted to the end of the element string
Example 2:
If offset is negative, truncate it from right to left. If it is negative, you must add a space ${ARRAY [@]:-n:-m} or ${ARRAY [*]:-n ARRAY m} after the colon.
${ARRAY [@]:-n m}: from right to left, the element string offset is numbered from right to left as-1 to-n, the starting position of the intercept is-n, and m characters are taken. ${ARRAY [@]:-n:-m}: from right to left, the element string offset is numbered from right to left as-1 to-n, the start position of the intercept is-n, and the end position is-m characters.
It is important to keep in mind that once an array is defined, you can only append elements to one by one in the array, or modify element values, and cannot add elements in batches. Batch assignment batch is array initialization.
ARRAY [${# ARRAY []}] = the number of value elements plus 1 to assign
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.