Universal Data Mover Variables - Types
Script Variables
Script variables are user-defined variables that are visible only to a called script, and any of its children, for which they have been defined. When the called script has ended, the script variables' definitions are removed from the scripting engine environment.
You must use the call command to define script variables. The variables are specified as parameters in a call command, after the script name, that loads and executes a script. They are created during execution of the script.
The value of a script variable cannot be changed once it has been created.
(For detailed information on defining script variables, see Universal Data Mover Script Files.)
Global Variables
Global variables are variables that are visible at all script levels.
They are permanent in scope and, once defined, last until the UDM Manager is terminated. Once defined, a global variable cannot be undefined, but its value can be changed by issuing another set command.
Global Variable Types
There are two types of global variables:
Issuing the set command by itself with no arguments displays all user-defined and built-in variables.
Global Variables Information
Each global variable includes the following information:
Name | Identifies a variable as either a UDM pre-defined variable (built-in variable) or a user-defined variable. A variable is referenced in a script by this name. |
Attribute | Optional entry that can be included in a variable reference. It provides additional information about a variable (see Variable Attributes). |
Value | Assigned by the user and/or provided by UDM, depending on the variable. Built-in variables have pre-defined and/or user-defined values. All user-defined variables have user-defined values. |
Scope of Script and Global Variables
A variable's scope is its visibility throughout the scripting environment.
Script variables supersede global variables in precedence. That is, if a script variable has the same name as an existing global variable, any references to that variable name will result in the script variable value, not the global variable value.
If more than one script variable exists with the same name, the script variable defined in the last call command has precedence.
For example, if UDM encounters the $(variable_name) sequence, it first checks to see if a variable with a matching name was passed into the script it currently is executing. If so, UDM uses this variable's value. If not, UDM goes up the chain of calling scripts and uses the value of the first instance of a variable that it finds that matches the name in the sequence.
If no variable with a matching name was passed into any script along the chain, UDM looks to see if a global variable exists with the name. If one is found, its value is used. If no instances are found anywhere, an error is issued.
Variable Scope Scripts
The following three scripts demonstrate variable scope:
script1.udm
set var1="a global variable" set var2="a global variable" set var3="a global variable" print msg="The value of var1 is $(var1)" print msg="The value of var2 is $(var2)" print msg="The value of var3 is $(var3)" call script2.udm var1="passed into script2" var2="passed into script2"
script2.udm
print msg="The value of var1 is $(var1)" print msg="The value of var2 is $(var2)" print msg="The value of var3 is $(var3)" call script3.udm var1="passed into script3"
script3.udm
print msg="The value of var1 is $(var1)" print msg="The value of var2 is $(var2)" print msg="The value of var3 is $(var3)"
Running UDM and calling script1.udm produces the following results:
Processing script: script1.udm The value of var1 is a global variable The value of var2 is a global variable The value of var3 is a global variable Processing script: script2.udm The value of var1 is passed into script2 The value of var2 is passed into script2 The value of var3 is a global variable Processing script: script3.udm The value of var1 is passed into script3 The value of var2 is passed into script2 The value of var3 is a global variable Finished processing script: script3.udm Finished processing script: script2.udm Finished processing script: script1.udm
User-Defined Variables
User-defined variables are defined using the set command. They can have any name — except that they cannot begin with an underscore ( _ ) character — and any value.
A user-defined variable can be called within any script or in an interactive session:
set variable_name=variable_value
The following example creates a user-defined variable called test:
set test="This is a test."
To assign a value to a variable that has one or more spaces in it, the value must be quoted:
set lonvar="This variable has a rather long value."
Multiple user-defined variables can be set with a single call to the set command, listing each variable's name / value pair in succession, separated by spaces:
set varname1=value1 varname2=value2 varname3=value3