{"id":6762,"date":"2015-06-18T05:09:33","date_gmt":"2015-06-18T12:09:33","guid":{"rendered":"http:\/\/blog.networkpresence.co\/?p=6762"},"modified":"2015-06-18T05:09:33","modified_gmt":"2015-06-18T12:09:33","slug":"some-bash-isms","status":"publish","type":"post","link":"http:\/\/blog.networkpresence.co\/?p=6762","title":{"rendered":"Some Bash-isms"},"content":{"rendered":"<p>Being a &#8220;code daily&#8221; type of open-source SysAdmin\/Operations Manager, I&#8217;ll post here a &#8216;tricks &#038; tips&#8217; that I&#8217;ve found useful when using and programming in the Bash Shell.<\/p>\n<p>This one notes how to replace a Bash variable name with another variable name. I know that the best practice here is to use one of the many forms of Arrays that Bash provides, but this is applicable to a situation where an Array is not available, and there&#8217;s a number of Bash variables containing data that are able to have their variable names computed\/calculated. eg: getting passed a shell or process&#8217; environment to a Bash script.<\/p>\n<p>For example\/to demonstrate:<\/p>\n<p><code># initialise<br \/>\nfirst_last1=10 ; first_last2=20 ; first_last3=30<br \/>\n# process<br \/>\ncount=1<br \/>\nwhile [ $count -le 3 ]; do<br \/>\n  TMP=\"first_last$count\"<br \/>\n  echo Variable named first_last$count = ${!TMP}<br \/>\n  let \"count+=1\"<br \/>\ndone<\/code><\/p>\n<p>Yields results of:<\/p>\n<p><code>Variable named first_last1 = 10<br \/>\nVariable named first_last2 = 20<br \/>\nVariable named first_last3 = 30<\/code><\/p>\n<p>FYI,<br \/>\nRichard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Being a &#8220;code daily&#8221; type of open-source SysAdmin\/Operations Manager, I&#8217;ll post here a &#8216;tricks &#038; tips&#8217; that I&#8217;ve found useful when using and programming in the Bash Shell. This one notes how to replace a Bash variable name with another &hellip; <a href=\"http:\/\/blog.networkpresence.co\/?p=6762\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,54],"tags":[51,466],"class_list":["post-6762","post","type-post","status-publish","format-standard","hentry","category-network-presence","category-rich","tag-bash","tag-devops"],"_links":{"self":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/6762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6762"}],"version-history":[{"count":4,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/6762\/revisions"}],"predecessor-version":[{"id":6766,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/6762\/revisions\/6766"}],"wp:attachment":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6762"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}