{"id":1358,"date":"2019-06-14T15:19:26","date_gmt":"2019-06-14T20:19:26","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1358"},"modified":"2019-06-14T15:19:26","modified_gmt":"2019-06-14T20:19:26","slug":"bash-array-dynamic-name","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/bash-array-dynamic-name\/","title":{"rendered":"Bash Array Dynamic Name"},"content":{"rendered":"\n

Sometimes you want to have dynamic array names to simplify code. Below is one way of making the array name dynamic in a loop.<\/p>\n\n\n

\n#!\/bin\/bash\n\nsection1=(\n fs-01\n fs-02\n)\nsection2=(\n fs-03\n)\n\nfunction snap() {\n  tag=$1\n  echo\n  echo "TAG: $tag"\n  x=$tag\n  var=$x[@]\n  for f in "${!var}"\n  do\n    echo "fss: $f"\n  done\n}\n\nsnap "section1"\nsnap "section2"\n<\/pre><\/div>\n\n\n

And output like this.<\/p>\n\n\n

\n# .\/i.sh\n\nTAG: section1\nfss: fs-01\nfss: fs-02\n\nTAG: section2\nfss: fs-03\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"

Sometimes you want to have dynamic array names to simplify code. Below is one way of making the array name<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1358","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1358"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1358\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}