TCL essentials for network automation

Variable initialization

To initialize a variable the set command is used. For ex, to assign the variable i with the value 3, set i 3 is used.

 

Incrementing values

To increment the value of the above variable i, the command incr i is used.

Printing values

The command puts is used to print value of variables, buffers on the screen.

While loop

A basic while loop command syntax is provided below.

 

set i 2

while {$i < 30} {

puts “Hi”

incr i}

 

The loop will print the value Hi till the value of i is less than 30.

 
Regular expressions 

Regular expressions are useful in scenarios where patterns need to be matched.

For ex, to find the IP address, 192.168.1.20, occurrence in a expect_out(buffer) the command [regexp {192.168.1.20}$expect_out(buffer)] is used.

This is a sample content from the book Network Test Automation with TCL and Expect

Become a Network Testing Expert with our Video Course Click Here