Within my Tcl script I’m building source code in another language. Let it be gnuplot source for example. I have Tcl code like this:
# `script' variable contains gnuplot source code
set script {
set terminal pdf
set output "chart.pdf"
set title "[makeTitle]"
plot "$dataFile" using 1:2 title ""
}
# Then I write `script' to file for later execution
Notice that script variable contains command call (makeTitle) and variable substitution (dataFile). The source code itself contains new lines, double quotes.
Question: how can I simply “evaluate” this variable to substitute command calls by their results and variables by their values? Expected result should look like this:
set terminal pdf set output "chart.pdf" set title "R(S) Dependence" plot "r_s.txt" using 1:2 title ""
You’re looking for the subst command: