Index

<datatype> name = value

Create a new scalar variable and assign it an initial value.

Arguments:
name
The name to give the variable. This must be unique within the current block of commands (see below).
value
The value to give the variable. This can be any expression that is compatible with the specified datatype.

Example:
The following example declares a string variable, then prints it.
 String s = "This is a test string.\n"
 print $s
Example 2:
The following example shows the effect of declaring two variables with identical names in nested blocks of commands. The text variable is declared both outside the while() loop and within it. This results in two variables, one that is only visible to statements within the body of the while() loop, and another that is potentially visible in both places but becomes hidden by the nested declaration until the the loop completes. Note that statements in the while loop that precede the nested declaration see the outer declaration.
 String text = "Outer.\n"
 print "A ", $text
 while($iteration < 1) {
   print "B ", $text
   String text = "Nested.\n"
   print "C ", $text
 }
 print "D ", $text
This produces the following output:
 A Outer
 B Outer
 C Nested
 D Outer
Context:
Variables can be declared anywhere in a script, but they must have unique names within the enclosing block of commands. A block of commands is a group of commands that are enclosed within braces. Examples are the bodies of loops, the bodies of if statements, and the bodies of user-defined commands.
Martin Shepherd (9-Oct-1997)