OSF DCE Administration Guide--Core Components

OSF DCE Administration Guide—Core Components
2.12 Creating New Commands
The DCE control program provides a powerful and comprehensive set of commands for
controlling and monitoring DCE operations. But the exact uses to which DCE is put by
end users is unpredictable. Consequently, it’s quite likely that some administrators will
need additional commands to meet very specific needs. The proc command offers an
easy way to create additional commands that look and behave just like built-in
commands such as set, list, and while. But unlike built-in commands, which are written
in C, commands created with proc are written using scripts, as follows:
dcecp> proc div {x y} {expr $x/$y}
dcecp>
The proc command takes three arguments: the procedure name, a list of names of
procedure arguments, and the dcecp script that forms the body of the new procedure.
Our new procedure div requires two arguments. For example:
dcecp> div 12 4
3
dcecp>
By default, proc assumes all variables are local variables. That is, their names and
values are set only within the procedure and they expire when the procedure completes.
The following command produces an error because variables x and y have not been set
within the procedure:
dcecp> set x 15
15
dcecp> set y 3
3
dcecp> proc div {} {expr $x/$y}
dcecp> div
Error: can’t read "x": no such variable
You can import global variables (variables defined outside the procedure) by using the
global command:
dcecp> set x 15
dcecp> set y 3
dcecp> proc div {} {
> global x y
> expr $x/$y
> }
dcecp> div
5
dcecp>
Once you import a global variable, it persists for the duration of the procedure. Your
procedure can change the value of the variable by using unset and set. The new value
2 24 Tandem Computers Incorporated 124243