Top
Systemwalker Operation Manager  Reference Guide
FUJITSU Software

15.1.3 Syntax of Systemwalker Script

This section describes the syntax of Systemwalker Scripts.

Variables

Variable names can be formed with any number of alphanumeric characters beginning of an alphabet. The variable names are case-sensitive and may include underbars (_).

Syntax

The syntax and interpretation of the Systemwalker Script language are defined as follows.

Separating commands

Commands in script lines are separated by line breaks or semicolons (;).

Example:

The following example stores a value in each of the variables abc and def:

set abc ABC
set def DEF

or

set abc ABC ; set def DEF
Variable substitution using dollar sign ($)

Variable substitution uses the dollar sign ($). Variable substitution means that referring to values stored in variables. Variable substitution attempted on a variable whose value is not defined results in a script error, which will cause an abnormal termination.

Example:

The following example stores the value stored in variable abc in other variable def:

set abc ABC
set def $abc
Command substitution using brackets ([ ])

Some script commands generate return values. Command substitution corresponds to referring to a return value at a command caller when a command is called. Command substitution uses brackets ([]).

Example:

The following example stores the result of arithmetic operation (3 + 2) in variable abc:

set abc [ expr 3 + 2 ]
Separating words in a command

Words in a command are separated by spaces or tabs. Separation of words in a command indicates that of command name, first argument, second argument and so on.

Variable and command substitutions within a word

When a dollar sign ($) is included in a word, variable substitution is performed, namely the word is replaced by the value of the variable. When brackets ([ ]) are included in a word, command substitution is performed and the word is replaced by the return value of the result of a command.

Command substitution is recursively performed, while variable substitution is done only once.

Example:

The following example recursively performs command substitution and stores the result of computation:

set abc [ expr [expr 1 + 1] + 2 ]

Note:

Since the expr command is capable of interpreting nested expressions, a math expression should not be written as indicated in the above example, but should be written as follows.

set abc [ expr (1 + 1) + 2 ]
Specifying a word using double quotations ("")

Words between two double quotations ("") are treated as a single word. Words with missing close double quotations result in a syntax error. The double quotation pair itself is not interpreted as part of a word.

Example:

The following example stores character string 123 in variable abc:

set abc "123"

The double quotation proceeded by a backslash (\) is treated as an ordinary character rather than being interpreted as a word enclosing symbol. For substitutions of backslash mark, see "Escape sequence (backslash-sign substitution) using backslash sign (\)".

Example:

The following example stores character string 123" in variable abc:

set abc "123\""

Although the semicolons (;), close brackets (]), and spaces (including line breaks) included in double quoted words are treated as ordinary characters, command and variable substitutions are performed.

Example:

The following example stores a character string containing spaces and variable substitution:

set abc "123"
set str "abc $abc def"

In this instance, the character string to be stored in variable str is abc 123 def.

Specifying a word using braces ({})

Words between two braces ({}) are treated as a single word. Words with missing closing braces result in a syntax error. The brace pair itself is not interpreted as part of a word.

Example:

The following example stores character string 1{2}3 in variable abc:

set abc {1{2}3}

The brace preceded by a backslash (\) is not interpreted as a word enclosing symbol. "\{" and "\}" included in a braced word will not be replaced by "{" and "}", respectively.

For details, see "Word enclosing symbols and backslash-sign substitutions".

Example:

The following example stores a character string containing braces:

set abc {123\}}

Here, character string 123\} is stored in variable abc.

The semicolons (;), close brackets (]), and spaces (including line breaks) included in braced words are treated as ordinary characters, and command and variable substitutions are not performed.

Example:

The following example stores a character string containing spaces:

set abc "123"
set str {abc $abc def}

Here, the character string to be stored in variable str is abc $abc def.

Escape sequence (backslash-sign substitution) using backslash sign (\)

If a word contains a backslash sign (\), the combination of \ and the character that follows is interpreted as an escape sequence and backslash-sign substitution is performed.

Shown below are types of backslash-sign substitution.

Sequence

Replaced by

\a

Bell

\b

Backspace

\f

Form feed

\n

Line break

\r

Carriage return

\t

Tab

\v

Vertical tab

\<line break>

Blank character (continuation line)

\"

Single double quotation that is not interpreted as a word enclosing symbol

\{

Single open brace that is not interpreted as a word enclosing symbol

\}

Single closing brace that is not interpreted as a word enclosing symbol

\\

Single backslash sign "\"

Note:

Any backslash sign must not be followed by any character other than the above.

Word enclosing symbols and backslash-sign substitutions

While all \s included in double quoted words are replaced by their corresponding characters or symbols, those included in braced words are not replaced except for "\<line break>."

Example:

When \ included in a braced word is not replaced:

set abc "C:\\tmp"
set def {C:\tmp}

Here, character string C:\tmp is stored in both variables abc and def.

Example:

When \ included in a braced word is replaced:

set abc "123\
456"
set def {123\
456}

Here, character string 123 456 is stored in both variables abc and def.

The "\{" and "\}" included in braced words are not replaced by their corresponding symbols. "\\" included in braced words are not replaced either; the latter \ loses the special meaning as an escape character in "\<line break>", "\{", and "\}."

Example:

When "\" loses the meaning as an escape character:

set abc {123\\}

Here, string 123\\ is stored in variable abc.

Note

As described above, the following strings cannot be written as braced words.

Example: A string ending with \

C:\tmp\

Example: A string with a missing brace

123}

Example: Strings having a \ preceding the line break

C:\tmp\
D:\tmp\
Handling of character strings in conditional expressions

The conditional expressions that are given in if or while statements are interpreted as mathematical expressions. Thus, if you want to have conditional expressions interpreted as string expressions, it is required to enclose the strings with double quotations. This requirement also applies to specify special characters that have true or false values (yes, no, true, and false).

Example 1:

The following example determines whether the value of variable a is string xyz:

if {$a == "xyz"} {
      puts ok
}

Example 2:

The following example repeats processing as long as the condition is true.

set i 0
while {"true"} {
      incr i
      if {$i > 5} {
            break
      }
}
Commands for manipulating strings

Double quoted strings are evaluated as mathematical expressions when it is possible to interpret the entire strings as a numeric. To precisely compare strings, it is recommended that the "15.2.19 string (Manipulate Character Strings)" command (a command that manipulates strings) be used to evaluate conditional expressions.

Example:

The following example determines whether the value of variable a is string 01:

if {[string compare $a 01] == 0} {
      puts ok
}

If the above if statement is replaced as shown below, the condition is true even if the value of variable a is 1 or 001.

if {$a == "01"}
Comment line

Any line or command that begins with # and ends with a line break is interpreted as a comment.

Example:

# Initialize the variable.
set abc 0

Note

Note the following when entering a comment:

  • Do not put an opening brace or closing brace in a comment line.

  • Do not put a continuation line (\<line break>) in a comment line or in a line right before the comment line.

  • Do not put a comment into conditional expression in the evaluation statements such as "if" or "while" statement.