{"id":668,"date":"2014-06-02T12:34:17","date_gmt":"2014-06-02T19:34:17","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=668"},"modified":"2014-06-05T10:21:38","modified_gmt":"2014-06-05T17:21:38","slug":"multi-array-in-bash","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/multi-array-in-bash\/","title":{"rendered":"Multi-Array in Bash"},"content":{"rendered":"

Well kind of... \u00a0When you are used to working in Python or any real language then Bash arrays are pretty lame. \u00a0But it can help in a few circumstances when you have to use Bash.<\/p>\n

\r\n# cat bash_array.sh\r\n#!\/bin\/bash\r\n# Array pretending to be a Pythonic dictionary\r\nARRAY_DETAILS=( "10.51.20.63:Host1:Solaris"\r\n                "10.51.20.80:Host2:Linux"\r\n                "10.20.50.11:Host3:Windows" )\r\n\r\nfor hostDetails in "${ARRAY_DETAILS[@]}" ; do\r\n  arrIN=(${hostDetails\/\/:\/ })\r\n  IP=${arrIN[0]}\r\n  NAME=${arrIN[1]}\r\n  TYPE=${arrIN[2]}\r\n  printf "Hostname %s with IP %s and is type %s.\\n" "$NAME" "$IP" "$TYPE"\r\ndone\r\n<\/pre>\n

And the result looks like this:<\/p>\n

\r\n# .\/bash_array.sh\r\nHostname Host1 with IP 10.51.20.63 and is type Solaris.\r\nHostname Host2 with IP 10.51.20.80 and is type Linux.\r\nHostname Host3 with IP 10.20.50.11 and is type Windows.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Well kind of… \u00a0When you are used to working in Python or any real language then Bash arrays are pretty<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-668","post","type-post","status-publish","format-standard","hentry","category-bash"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/668","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=668"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/668\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}