使用bash here-doc“文件意外末尾"时出错. [英] Error when using a bash here-doc "unexpected end of file"
问题描述
我在代码的最后一行(为空)上标记了以下错误:
I get the following error that is flagging on the last line of my code (which is empty):
syntax error: unexpected end of file
我不知道为什么这么说.我只是想使用here-doc
进行ssh连接:
I can't figure out why it's saying this. I'm simply trying to use a here-doc
for an ssh connection:
#!/bin/sh
connectToServer() {
ssh -t root@$1 <<- ENDSSH
echo "Connected to server!"
ENDSSH
}
connectToServer $1
此代码有什么问题?
编辑
感谢那些帮助我解决此问题的人.我的脚本有几处错误;我在行上使用空格:
Thanks to those of you who helped me to troubleshoot this. There were a couple of things wrong with my script; I was using spaces on the line:
echo "Connected to server"
代替制表符.我在结束ENDSSH
之前也包含空格,这导致了EOF.这些更改是我的问题的一部分,但解决该问题的最后一件事是删除了在我关闭ENDSSH
之后出现的另一个空格字符.
instead of tab characters. I was also including spaces before the closing ENDSSH
which was causing the EOF. These changes were a part of my problem, but the final thing that resolved it was removing an additional space character that appeared AFTER my closing ENDSSH
.
推荐答案
问题是关闭ENDSSH
之前的空格.删除ENDSSH
之前的所有前导空格.
Problem is spaces before closing ENDSSH
. Take out all the leading spaces before ENDSSH
.
这篇关于使用bash here-doc“文件意外末尾"时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!