In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about the array script programming of Shell. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
Array (array)
1. Variables: memory space that stores a single element
two。 Array: a continuous memory space that stores multiple elements, equivalent to a collection of variables.
3. Array name and index
Index: the number starts with 0 and belongs to a numeric index; Note: indexes can support the use of custom formats, not just numeric formats, that is, associated indexes, which are supported after the bash5.0 version; bash--version view bash versions such as: custom indexes are letters and words (first); bash arrays support sparse formats (indexes are not contiguous).
4. Declare array
Declare-aARRAY_NAME (array name) declare-AARRAY_NAME: associative array (array must be declared first) Note: the two cannot be converted to each other temporarily (exit); declare before use; array assignment 1. Assignment of array elements
(1) assign only one element at a time
ARRAY_ name [index] = VALUEweekdays [0] = "Sunday" weekdays [4] = "Thursday" echo$ {weekdays [0]} displays an element of the array echo$ {weekdays [4]} unsetweekdays [0] deletes an index in the array unsetweekdays deletes all index quotation marks in the array: the form "axib" must be in quotation marks
(2) assign all elements at once:
ARRAY_NAME= ("VAL1", "VAL2", "VAL3"...)
Reference array
(1) reference array elements:
(2) reference all elements of the array:
(3) length of the array (number of elements in the array):
(4) Delete an element in the array: result in sparse format
(5) Delete the entire array:
Advanced variable usage
Typed variables Shell variables are generally untyped, but bashShell provides declare and typeset commands to specify the type of variable, and the two commands are equivalent Declare [options] variable name-r declares or displays read-only variables-I define variables as integers-a defines variables as arrays-A defines variables as associative arrays-f displays all function names and their contents defined before this script-F displays only all function names defined before this script-x declares or displays environment variables and functions-l declares variables as lowercase declare-lvar=UPPER- U declares the variable as the uppercase letter declare-uvar= low 7, The eval command eval command will scan the command line first for all replacements Then execute the command. This command applies to variables that cannot be scanned at one time. It scans variables twice.
This is what the editor shares with you about Shell array scripting. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.