puts "Hello world !"
In this post we will see how to read keyboard input from console using TCL script. Some time we need to take input from user to proceed further, for example adding two numbers. Here is syntax to read :
gets channel_ID variable_Name
Here, channel_ID is id of channel . It specify from where we have to read. To read from console we need to use stdin (standard input) as channel ID.
variable_Name is name of variable where we have to store that text.
Let us check one sample example.
puts "what is your favourite colour ?" gets stdin name_of_colour puts "Colour is $name_of_colour"
what is your favourite colour ?
Colour is red
Here is another example to add two numbers entered by user :
puts "Enter first number for addition:" gets stdin first_number puts "Enter second number for addition:" gets stdin second_number set answer [expr $first_number + $second_number] puts "Addition of $first_number and $second_number is : $answer"
Output will be :
Enter first number for addition:
Enter second number for addition:
Addition of 33 and 11 is : 44