Bash脚本没有运行tclsh

时间:2015-01-29 02:56:57

标签: bash tcl

我可以正确地在远程家庭上运行bash。我在远程主机上安装了TCL但是无法运行TCL。当我运行这个脚本时,我没有错误。

#!/bin/bash
ssh root@XXX.XXX.XXX.XXX << 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

1 个答案:

答案 0 :(得分:5)

默认情况下,Heredocs会在其中展开变量,因此除非您在外部脚本中导出[open $filename "w"]变量,否则open "w"]会更改为filename(以及其他地方的类似更改)。如果您不希望进行扩展,请引用您的印记:

ssh root@XXX.XXX.XXX.XXX <<'EOF'

script='content'

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

EOF