You obtain the results of a command by placing the command in square brackets ([]). This is the functional equivalent of the back single quote (`) in sh programming, or using the return value of a function in C.
As the Tcl interpreter reads in a line it replaces all the $variables with their values. If a portion of the string is grouped with square brackets, then the string within the square brackets is evaluated as a command by the interpreter, and the result of the command replaces the square bracketed string.
puts [readsensor [selectsensor]]
The exceptions to this rule are as follows:
set x abc
puts "A simple substitution: $x\n"
set y [set x "def"]
puts "Remember that set returns the new value of the variable:"
puts " X: $x Y: $y\n"
set z {[set x "String within quotes within braces"]}
puts "Note curly braces: $z\n"
set a "[set x {String within braces within quotes}]"
puts "See how the set is executed: $a"
puts "\$x is: $x\n"
set b "\[set y {This is a string within braces within quotes}]"
# Note the \ escapes the bracket, and must be doubled to be a
# literal character in double quotes
puts "Note the \\ escapes the bracket:\n \$b is: $b"
puts "\$y is: $y"A simple substitution: abc
Remember that set returns the new value of the variable:
X: def Y: def
Note curly braces: [set x "String within quotes within braces"]
See how the set is executed: String within braces within quotes
$x is: String within braces within quotes
Note the \ escapes the bracket:
$b is: [set y {This is a string within braces within quotes}]
$y is: def