OSF DCE Administration Guide--Core Components

Using the DCE Control Program Command Language
Although it’s fairly easy for an administrator to scan a list and extract the necessary
information from it, scripts operate in the dark, feeling their way through information.
When scripts search for specific information, they usually ignore the notion of lists,
operating instead on the collection of characters (called a string) that makes up a list.
The DCE control program provides a set of commands to operate on strings, letting you
construct, parse, compare, extract values from, and modify strings.
2.13.1 Constructing Strings
Often, scripts need to construct strings for use in other commands or for displaying on
the screen for users. The DCE control program provides a format command that you use
to construct strings for use by your script.
The format command substitutes variables where needed. The following example
constructs the variable _dcp_host_entries by using the format command to prepend the
cell name string (the string type is indicated by %s) to the string /hosts. The cell name
is contained in the _c convenience variable.
dcecp> set _dcp_host_entries [format "%s/hosts" $_c]
/.../my_cell.goodco.com/hosts
dcecp>
The format command can also convert arguments between differing forms including
decimal, octal, hexadecimal, floating-point, and scientific notation. You can also specify
to print or omit signs for signed numbers, right or left justify output, and pad with spaces
or zeroes. The following examples convert the integer 8 to its octal equivalent. The
second example shifts the output nine character spaces to the right.
dcecp> format %1o 8
10
dcecp> format %9o 8
10
dcecp>
2.13.2 Parsing Strings
The DCE control program includes a scan command that parses strings and then converts
and stores relevant parts of strings in variables. This capability is useful, for instance,
when converting information returned by a previous command into data that can be input
to another command. The syntax for the scan command is as follows:
scan "string""format"[varname [varname]...]
You can specify the string literally or by using a variable. The format section controls
parsing, ignoring blanks and tab characters you might have included in the format
124243 Tandem Computers Incorporated 2 27