首页 > 其他分享 >EOF:warning: delimited by end-of-file

EOF:warning: delimited by end-of-file

时间:2022-11-26 14:32:53浏览次数:37  
标签:脚本 delimited EOF send sh warning expect && end

一、问题描述

1、脚本
#############################################
cat ${remoteip}|while read line
do
/usr/bin/expect<<EOF
set timeout 20
spawn ssh -p ${remoteport} ${remoteuser}@${line}
expect {
"yes/no" {
send "yes\r"
expect_continue
}
"assword" { #此处不写password是因为有的操作系统是小p,有的操作系统是大P
send "${remotepass}\r"
}
}
expect "*"
send "cd ${remotebindir} && sh stop.sh && sleep 2 && sh start.sh\r"
expect "*"
send "exit\r"
expect eof
EOF
sleep 1
done

2、说明
为了让脚本看起来更直观,我将while do到done之间的代码往右缩进了俩字符
这时使用vi打开开头的EOF是黄色的,第二个EOF却是红色的
运行脚本直接报错
warning: here-document at line 16 delimited by end-of-file (wanted `EOF') #16行这个不准,脚本作了修改

二、解决办法

开头EOF没要求
结束的EOF左右必须不能有换行、制表符或者空格
将第二个EOF左边的空格删掉,颜色也变成黄色(尽管这样看着代码不怎么好看)
可以正常执行

标签:脚本,delimited,EOF,send,sh,warning,expect,&&,end
From: https://blog.51cto.com/u_13236892/5888924

相关文章