Refer to some shell Array Operations and usage to construct and traverse a two-dimensional array, as shown below:
# Sites = ("www.a.com www. B .com www.c.com www.d.com" "www.e.cn www.f.cn") separated by Spaces ") 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_inner_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 space rather than comma. In addition, the usage of traversing array elements is as follows:
For ele in $ {arrayname [*]} do echo $ ele done
I still know little about shell usage and still need to work hard ~~