Reputation: 499
I am trying to log down the variable_A value by redirect the echo to variable_A.log as below:
echo $variable_A >> variable_A.log
But instead of printing the value to my log file, it actually treat "$varaible_A >> variable_A.log" as string and printed on the prompt.
Upvotes: 1
Views: 13112
Reputation: 246817
This is less efficient, but easy to grok:
exec echo $message >> filename
In an interactive tclsh session, it will work without the exec
due to the way the defalt unknown
procedure is defined.
Upvotes: 2
Reputation: 137577
To append a value to a file, you need to open the file in the right mode and use the two-argument form of puts
(the one-argument form is defaulting to writing to stdout
). Let's make a trivial procedure to do it:
proc appendToFile {message >> filename} {
set f [open $filename "a"]; # The “a” is the key part
puts $f $message
close $f
}
Now we can use that dead easy:
appendToFile $variable_a >> variable_A.log
The >>
in this case is just syntactic sugar. It has no value at all other than to make what you're doing easier to read. (>>
is a legal — but quite strange — variable name in Tcl.)
Upvotes: 2