79 lines
2.3 KiB
HTML
79 lines
2.3 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||
|
<meta http-equiv="Content-Type" content=
|
||
|
"text/html; charset=utf-8">
|
||
|
<title>local - Assign a local variable in a function</title>
|
||
|
<LINK rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</HEAD>
|
||
|
<body bgcolor="#FFFFFF">
|
||
|
<!-- Java sync-link -->
|
||
|
<SCRIPT LANGUAGE="Javascript" SRC="../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
||
|
|
||
|
|
||
|
|
||
|
<h2>local - Assign a local variable in a function</h2>
|
||
|
|
||
|
<strong>Synopsis</strong>
|
||
|
|
||
|
<p><strong>local</strong> [ <em>name</em> [ <em>=value</em> ] ... ]</p>
|
||
|
|
||
|
<p><strong>Description</strong></p>
|
||
|
|
||
|
<p>You can use <strong>local</strong> to make a variable local to a
|
||
|
function. When a variable is made local, it inherits the initial
|
||
|
value and exported and read-only attributes from the variable with
|
||
|
the same name in the surrounding scope, if there is one. Otherwise,
|
||
|
the variable is initially unset.</p>
|
||
|
|
||
|
<p><strong>qsh</strong> uses dynamic scoping, so that if you make
|
||
|
the variable <em>alpha</em> local to function <em>foo</em>, which
|
||
|
then calls function <em>bar</em>, references to the variable <em>
|
||
|
alpha</em> made inside <em>bar</em> will refer to the variable
|
||
|
declared inside <em>foo</em>, not to the global variable named <em>
|
||
|
alpha</em>.</p>
|
||
|
|
||
|
<p>The special parameter <strong>-</strong> is the only special
|
||
|
parameter that can be made local . By making <strong>-</strong>
|
||
|
local, any shell options that are changed with <strong>set</strong>
|
||
|
inside the function are restored to their original values when the
|
||
|
function returns.</p>
|
||
|
|
||
|
<p><strong>Options</strong></p>
|
||
|
|
||
|
<p>None.</p>
|
||
|
|
||
|
<p><strong>Operands</strong></p>
|
||
|
|
||
|
<p>Each <em>name</em> specifies a variable in the current
|
||
|
environment. If a <em>value</em> is also specified, the value of
|
||
|
the variable is updated.</p>
|
||
|
|
||
|
<p><strong>Exit Status</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li>0 when successful.</li>
|
||
|
|
||
|
<li>>0 when called from outside of a function.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p><strong>Related information</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li><a href="export.htm">export - Set export attribute for
|
||
|
variables</a></li>
|
||
|
|
||
|
<li><a href="readonly.htm">readonly - Set read-only attribute for
|
||
|
variables</a></li>
|
||
|
|
||
|
<li><a href="set.htm">set - Set or unset options and positional
|
||
|
parameters</a></li>
|
||
|
|
||
|
<li><a href="unset.htm">unset - Unset values of variables and
|
||
|
functions</a></li>
|
||
|
</ul>
|
||
|
</body>
|
||
|
</html>
|
||
|
|