1

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
2
  • 1
    btw, you're also missing a HERE. Presumably that should be just before the echo "Exit". That one you don't want to quote, since you're using that heredoc as a POSIX-sh equivalent to a herestring. Commented Jan 29, 2015 at 3:09
  • Thanks @CharlesDuffy Everything is working great now :D Commented Jan 29, 2015 at 3:15

1 Answer 1

5

Heredocs expand variables inside them by default, so your [open $filename "w"] is changed to open "w"] (and similar changes elsewhere) unless you have a filename variable exported in your outer script. If you don't want that expansion to occur, quote your sigil:

ssh [email protected] <<'EOF'

script='content'

# intentionally not quoting this sigil, since in this case expansion is desired
tclsh <<HERE
$script
HERE

EOF
Sign up to request clarification or add additional context in comments.

2 Comments

And its always the simplest of things
I think it's easier at this point to start using separate files for things. Having everything all in one is all very well, but the confusion inevitably mounts after a while…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.