I am able to run bash on a remote home properly. I have TCL installed on the remote host but am not able to run TCL. When I run this script, I get no errors.
#!/bin/bash
ssh [email protected] << EOF
echo "Connected";
echo "CD TO ~";
cd ~;
echo "Create text file";
script='
set data "This is some test data.\n"
set filename "test.txt"
set fileId [open $filename "w"]
puts -nonewline $fileId $data
close $fileId
exit 0'
tclsh << HERE
$script
echo "Exit";
exit
EOF
HERE. Presumably that should be just before theecho "Exit". That one you don't want to quote, since you're using that heredoc as a POSIX-sh equivalent to a herestring.