{"id":1620,"date":"2020-03-06T00:31:43","date_gmt":"2020-03-05T21:31:43","guid":{"rendered":"https:\/\/artem.services\/?p=1617"},"modified":"2020-03-06T00:36:33","modified_gmt":"2020-03-05T21:36:33","slug":"1620","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1620&lang=en","title":{"rendered":"\u00a0BASH &#8212; The variable content of which refers to another variable"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-568\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/BASH-Logo.png\" alt=\"\" width=\"376\" height=\"159\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/BASH-Logo.png 376w, https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/BASH-Logo-300x127.png 300w\" sizes=\"(max-width: 376px) 100vw, 376px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>For example, there is the <strong>N<\/strong> number of variables, &quot;<strong>var_1<\/strong>&quot;, &quot;<strong>var_2<\/strong>&quot; and so on, the script takes as arguments only the number of the variable, and its contents should be in the new <strong>var<\/strong> variable.<\/p>\n<p>If you execute this script, passing it as argument &quot;<strong>1<\/strong>&quot;:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n.\/my_script.sh 1\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>my_script.sh<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\nvar_1='MY_VAR_NUMBER_1'\r\nvar_2='MY_VAR_NUMBER_2'\r\nvar_3='MY_VAR_NUMBER_3'\r\n\r\nvar=&quot;var_$1&quot;\r\necho $var\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>That script will return:<\/p>\n<pre>var_1<\/pre>\n<p>&nbsp;<\/p>\n<p>And we need the contents of the variable &quot;<strong>var_1<\/strong>&quot;. To do this, the &quot;<strong>echo<\/strong>&quot; command should look like this:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\necho &quot;${!var}&quot;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In this case, it will return:<\/p>\n<pre>MY_VAR_NUMBER_1<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; For example, there is the N number of variables, &quot;var_1&quot;, &quot;var_2&quot; and so on, the script takes as arguments only the number of the variable, and its contents should be in the new var variable. If you execute this script, passing it as argument &quot;1&quot;: &nbsp; my_script.sh &nbsp; That script will return: var_1 &nbsp; &hellip; <a href=\"https:\/\/artem.services\/?p=1620&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;\u00a0BASH &#8212; The variable content of which refers to another variable&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[415],"tags":[427,1267],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1620"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1620"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1620\/revisions"}],"predecessor-version":[{"id":1622,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1620\/revisions\/1622"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}