In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to define Shell array". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Bash supports one-dimensional arrays (not multidimensional arrays) and does not limit the size of the array. Similar to the C language, the subscripts of array elements are numbered starting with 0. The subscript is used to get the elements in the array, which can be an integer or an arithmetic expression whose value should be greater than or equal to 0.
Define array
In Shell, arrays are represented by parentheses, and array elements are separated by a "space" symbol. The general form of defining an array is:
Array name = (value 1, value 2. Value n)
For example:
Array_name= (value0 value1 value2 value3)
Or
Array_name= (value0value1value2value3)
You can also define individual components of an array:
Array_name [0] = value0array_name [1] = value1array_ name [n] = valuen
There can be no use of consecutive subscripts, and there is no limit to the range of subscripts.
Read array
The general format for reading array element values is:
${Array name [subscript]}
For example:
Valuen=$ {array_ name[n]}
Use the @ symbol to get all the elements in the array, such as:
Echo ${array_name [@]} gets the length of the array
Get the length of an array in the same way as you get the length of a string, for example:
# get the number of array elements length=$ {# array_name [*]} # or length=$ {# array_name [*]} # get the length of a single element of the array lengthn=$ {# array_ name [n]} "how to define the array" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.