Conditional Statements (GNU Radius Reference Manual)

Next: , Previous: , Up: radtest [Contents][Index]


12.2.9 Conditional Statements

Radtest provides two kinds of conditional statements: if and case.

If statement

An if statement in its simplest form is:

if cond stmt

where cond is a conditional expression and stmt is a valid radtest statement. Optional newline may be inserted between cond stmt.

In this form, if evaluates the condition and if it yields true, executes the statement. For example:

if $REPLY[NAS-IP-Address] = 127.0.0.1
 print "Request from localhost"

More complex form of this statement allows to select between the two statements:

if cond stmt-1 else stmt-2

Here, stmt-1 will be executed if cond evaluates to true, and stmt-2 will be executed if cond evaluates to false.

Notice, that an optional newline is allowed between cond and stmt-1 and right after else keyword. However, a newline before else constitutes an error.

If several statements should be executed in a branch of the if statement, use compound statement as in the example below:

if $REPLY_CODE != Accounting-Response
begin
 print "Accounting failed.\n"
 exit 1
end else
 print "Accounting succeeded.\n"

If statements can be nested to any depth.

Case statement

Case statement allows select a statement based on whether a string expression matches given regular expression. The syntax of case statement is:

case expr in
expr-1 ) stmt-1
expr-2 ) stmt-2expr-n ) stmt-n
end

where expr is a control expression, expr-1, expr-2 etc. are expressions evaluating to extended POSIX regular expressions (for the detailed description of these see Regular Expression Library in Regular Expression Library).

Case statement first evaluates expr and converts it to string data type. Then it evaluates each expr-n in turn and tests if the resulting regular expression matches expr. If so, the statement stmt-n is executed and the execution of case statement finishes.

The following example illustrates the concept:

case $COMMAND in
"auth.*") authenticate($LIST, no)
"acct") authenticate($LIST, yes)
".*") begin
 print "Unknown command."
 exit 1
 end
end

Bourne shell programmers should notice that:


Next: Loops, Previous: Interacting with Radius Servers, Up: radtest [Contents][Index]

AltStyle によって変換されたページ (->オリジナル) /