Variable substitution in TCL heredoc

204 views Asked by At
exec -- sftp [email protected] {<<
get $filename
quit}

How can i substitute $filename?

1

There are 1 answers

0
Donal Fellows On BEST ANSWER

To get variable substitution, use double quotes instead of braces. Standard Tcl rule, though maybe surprising to you in this situation. (I recommend putting the << outside as its own argument as I think it is clearer that way.)

exec -- sftp [email protected] << "
get $filename
quit"

You can also use the subst command. Sometimes that is clearer; it's largely equivalent (except for some very fine niceties that don't matter too much unless you're doing large templated documents).

exec -- sftp [email protected] << [subst {
    get $filename
    quit
}]