PreviousNext

Variable Substitution Provides a Convenient Shorthand

Like other programming languages, dcecp provides shorthand ways to express and use values. Variable substitution is one shorthand method that lets you represent a value - say, the name of an object in a CDS directory - as a variable.

Use the set command to establish a value for a variable. For readability, a variable name can consist of any combination of letters, numbers, and underscore characters. Use quotes or backslashes (\) to include spaces in variable names (although this is not usually recommended) or values. All of the following examples use valid variable names:

set a $I
set CDS_clearinghouse_name cambridge_ch
set DCE_user_1 "William Rosenberry"

The following example sets variable a to have a value of 7. The second use of the set a command without a value causes dcecp to display the current value of the variable.

dcecp> set a 7
7
dcecp> set a
7

Once you have established a value for a variable using the dcecp set command, the variable can be subsequently used elsewhere in your script or interactive command. The dcecp program uses the dollar sign to trigger insertion of the current value into the command word. A simple example is:

dcecp> set a 7
7
dcecp> expr $a+2
9

In this example we first set variable a to 7. In line 2, we use the expr command to add 2 to the value of a (7). The dollar sign triggers dcecp to insert the value 7. The last line shows the return value from the expr command.

A more relevant example might be:

dcecp> set a /.:/sec
/.:/sec
dcecp> object show $a
{RPC_ClassVersion
{01 00}}
{RPC_ObjectUUIDs
{06 3b 23 00 72 e5 e0 1d 8c b4 00 00 c0 8a df 56}}
{RPC_Group
{2f 2e 2e 2e 2f 77 61 72 64 5f 63 65 6c 6c 2e 6f 73 66 2e 6f 72
67 2f 73 75 62 73 79 73 2f 64 63 65 2f 73 65 63 2f 6d 61 73 74
65 72 00}}
{CDS_CTS 1994-05-23-17:21:37.481+00:00I0.000/00-00-c0-8a-df-56}
{CDS_UTS 1994-05-23-17:22:36.607+00:00I0.000/00-00-c0-8a-df-56}
{CDS_Class RPC_Group}
{CDS_ClassVersion 1.0}
dcecp>

Remove (undefine) a variable using the unset command as in the following example:

dcecp> unset a
dcecp> set a
Error: can't read "a": no such variable
dcecp>