74 lines
2.3 KiB
HTML
74 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>Functions</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>Functions</h2>
|
||
|
|
||
|
<p>The syntax of a function definition is</p>
|
||
|
|
||
|
<p>
|
||
|
<strong>[ function ]</strong> <em>name</em> <strong>( )</strong> <em>command</em>
|
||
|
</p>
|
||
|
|
||
|
<p>A function definition is a statement that when run installs a
|
||
|
function named <em>name</em> and returns an exit status of zero.
|
||
|
The <em>command</em> is normally a list enclosed between braces
|
||
|
(<strong>{</strong> <strong>}</strong>).</p>
|
||
|
|
||
|
<p>When <em>name</em> is specified as a simple command, <strong>
|
||
|
qsh</strong> runs <em>command</em>. The arguments to the simple
|
||
|
command temporarily become the positional parameters while the
|
||
|
function is running. The special parameter <strong>0</strong> is
|
||
|
unchanged. By using <strong>local</strong>, you can declare local
|
||
|
variables inside of the function. By using <strong>return</strong>,
|
||
|
you can end the function and resume execution with the next command
|
||
|
after the function call.</p>
|
||
|
|
||
|
<p><strong>Examples</strong></p>
|
||
|
|
||
|
<p>Here is an example of a function that provides a <strong>
|
||
|
qsh</strong> interface to the PING CL command.</p>
|
||
|
|
||
|
<pre>
|
||
|
ping()
|
||
|
{
|
||
|
# Initialize variables and make them local to this function
|
||
|
local nbrpkt='' waittime='' intnetadr='' msgmode='' pktlen='' ipttl='' host=''
|
||
|
local c
|
||
|
|
||
|
# Process the options
|
||
|
while getopts c:i:I:qs:T:v c
|
||
|
do case $c in
|
||
|
c) nbrpkt="NBRPKT($OPTARG)";;
|
||
|
i) waittime="WAITTIME($OPTARG)";;
|
||
|
I) intnetadr="INTNETADR('$OPTARG')"
|
||
|
host="*INTNETADR";;
|
||
|
q) msgmode='MSGMODE(*QUIET)';;
|
||
|
s) pktlen="PKTLEN($OPTARG)";;
|
||
|
T) ipttl="IPTTL($OPTARG)";;
|
||
|
v) msgmode='MSGMODE(*VERBOSE)';;
|
||
|
\?) print -u2 "Usage: ping [-c count] [-i seconds] [-I ipaddr] [-q]" \
|
||
|
"[-s size] [-T ttl] [-v] hostname"
|
||
|
return 1;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
# Run the command
|
||
|
shift $OPTIND-1
|
||
|
system ping ${host:-$1} $intnetadr $nbrpkt $waittime $msgmode $pktlen $ipttl
|
||
|
}
|
||
|
</pre>
|
||
|
</body>
|
||
|
</html>
|