In Variables In TCL, how to assign a value to a variable using set command. In this post we are going to discuss about the grouping of strings as a single argument. Arguments are data provided to a command. If we don't group them, they will be treated as several data and command will not perform its task as it is expected.
We can group multiple string/word as a single argument using "" and {}. But, they behave differently. In Variables In TCL, we have read that when we prefix $ with a variable, we read the value of that variable. It's true in the case of grouping with "" but not in the case of {}.
Here we are going to write a file named grouping.tcl and then we will run it as, tclsh grouping.tcl
# Assigning "circle" to shape variable.
set shape "circle";
# Displaying the shape value
puts "The shape is: $shape";
puts {The shape is: $shape}; # It will not display the shape value.
puts "The shape is: {$shape}"; # But it will display the shape value.
# Now we talk about escape sequence. characters following \ character.
puts "The shape is: \$shape"; # It will not display the shape value.
puts "I'm on line 1 and \n you're on line 2."; # Displayed on two lines.
puts "You're also on \
my line."; # Displayed on a single line.
If we group strings using "", there will be substitution of the variable value inside {}.
If we escape $ using \ then the variable value will not be substituted.
The escape sequence \n moves cursor to the next line. Also we can use other C language
escape sequences e.g. \t for tab to move cursor several places ahead.
If \ is immediately followed by a newline(e.g. enter key) then the following line will be treated as a part of the previous line. Only this escape sequence works in grouping with {}.
Happy reading and thank you. Meet you soon.
Comments
Post a Comment