OSF DCE Administration Guide--Core Components

OSF DCE Administration Guide—Core Components
exists. The following example script fragment returns an error message if the account
name does not exist in the list_of_group_entries variable:
set list_of_group_entries [group list $group -simplename]
if { [lsearch $list_of_group_entries $account_name] == -1} {
group add $group -member $account_name
} else {
error "Group \"$group\" already has an entry \
for \"$account_name\"."
}
2.9.2 Controlling Script Execution with Loops
Programming languages use loops to repeat operations as long as specified conditions
exist. The DCE control program offers three kinds of loops: foreach, while, and for.
The type of loop you use depends on the way conditions are specified.
2.9.2.1 The foreach Loop
When you want to perform a given operation on each element in a list, use the foreach
command. Remember that a list is a colletion of objects, or things enetered by you or
returned from a command.
The syntax is
foreach variable_name list body
The foreach command consists of a list, a script body, and a variable that represents each
element of the list, in turn. The command runs the script body on the element
represented by the variable and then sets the variable to be the next element in the list.
The following sample foreach command could be part of a script that manages hosts in a
DCE cell. This script fragment removes the host principal name from the registry if a
failure occurs while configuring the host in the cell. The foreach command looks at each
principal name in the cell. If the string commands find the host name listed in the output
from principal catalog, the script deletes the principal name from the registry.
foreach princ [principal catalog -simplename] {
if {[string match $host_name [string range $princ 0 \
[expr [string length $host_name] - 1]]] == 1} {
principal delete $princ
}
}
2 18 Tandem Computers Incorporated 124243