[Shell] a usage of constructing and traversing two-digit arrays
Source: Internet
Author: User
[Shell] constructs and traverses two-dimensional arrays. for a usage reference, see some operations on shell arrays. this provides a way to construct and traverse two-dimensional arrays, as shown below: [plain] the array elements are separated by spaces (& quot; wwwacomwwwbcomwwwccomwwwdcom & quot; www [shell] is used to construct and traverse two-dimensional arrays. refer to some operations of shell arrays to construct and traverse two-dimensional arrays: [plain] # Split the array element by space into sites = ("www.a.com www. B .com www.c.com www.d.com" "www.e.cn www.f.cn ") n_sites =$ {# sites [*]} # obtain the length of the one-dimensional sites array for (I = 0; I <$ n_sites; I ++ )); do inner_sites = ($ {sites [$ I]}) # assign a one-dimensional sites string to the array n_in Ner_sites =$ {# inner_sites [*]} # obtain the length of the two-dimensional sites array for (j = 0; j <$ n_inner_sites; j ++ )); do echo $ {inner_sites [$ j]} # echo site # do something done. it is worth noting that the separator in shell is a space instead of a comma. In addition, the array element Traversal function is [html] for ele in $ {arrayname [*]} do echo $ ele done.
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