{"id":116,"date":"2012-01-17T13:49:49","date_gmt":"2012-01-17T21:49:49","guid":{"rendered":"http:\/\/sobell.com\/mgsblog\/?p=116"},"modified":"2012-01-17T13:50:28","modified_gmt":"2012-01-17T21:50:28","slug":"the-local-builtin","status":"publish","type":"post","link":"https:\/\/sobell.com\/mgsblog\/archives\/116","title":{"rendered":"The local Builtin"},"content":{"rendered":"<p>You can use the <strong>local<\/strong> builtin only within a function. This builtin causes its arguments to be local to the function it is called from and its children. Without <strong>local<\/strong>, variables declared in a function are available to the shell that called the function (functions are run in the shell they are called from). The following function demonstrates the use of <strong>local<\/strong>.<\/p>\n<pre><code>$ <strong>demo ()<\/strong>\r\n&gt; <strong>{<\/strong>\r\n&gt; <strong>x=4<\/strong>\r\n&gt; <strong>local y=8<\/strong>\r\n&gt; <strong>echo \"demo: $x $y\"<\/strong>\r\n&gt; <strong>}<\/strong>\r\n$ <strong>demo<\/strong>\r\ndemo: 4 8\r\n$ <strong>echo $x<\/strong>\r\n4\r\n$ <strong>echo $y<\/strong>\r\n\r\n$<\/code><\/pre>\n<p>The <strong>demo<\/strong> function, which is entered from the keyboard, declares two variables: <strong>x<\/strong> and <strong>y<\/strong> and displays their values. The variable <strong>x<\/strong> is declared with a normal assignment statement while <strong>y<\/strong> is declared using <strong>local<\/strong>. After running the function, the shell that called the function has access to <strong>x<\/strong> but knows nothing of <strong>y<\/strong>.<strong><\/strong><strong><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use the local builtin only within a function. This builtin causes its arguments to be local to the function it is called from and its children. Without local, variables declared in a function are available to the shell &hellip; <a href=\"https:\/\/sobell.com\/mgsblog\/archives\/116\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[],"_links":{"self":[{"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/posts\/116"}],"collection":[{"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":10,"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":170,"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/posts\/116\/revisions\/170"}],"wp:attachment":[{"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sobell.com\/mgsblog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}