bash if 语句中的 EOF
我正在尝试在 Bash 中的 IF ELSE 语句中执行操作,但收到如下错误:
语法错误:文件结尾意外(期望“fi”)
现在我对此很陌生,所以我的问题的解决方案可能不应该那么困难:)
if [ "$DAYNAME" = 'Sunday' ]; then
echo 'The backup will be uploaded'
ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
put $filetoday
delete ${filethreeweeksago}
quit
EOF
fi
当然变量已经填满了。
我认为这与 EOF 表示法有关,因为当我删除它们时,问题就消失了。不幸的是,我不知道如何使用没有 EOF 符号的代码。
谁能告诉我为什么会出现这个错误?
I am trying to do an action in a IF ELSE statement in Bash, but receive an error like this one:
Syntax error: end of file unexpected (expecting "fi")
Now I am quite new to this, so probably the solution to my problem should not be that difficult :)
if [ "$DAYNAME" = 'Sunday' ]; then
echo 'The backup will be uploaded'
ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
put $filetoday
delete ${filethreeweeksago}
quit
EOF
fi
Of course the vars are already filled.
I think it has to do with the EOF notation, because when i remove them, the problem disapears. Unfortunatly I don't know how to use the code without the EOF notation.
Can anyone tell me why this error is comming up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
删除空白,它应该可以工作:
Drop the blanks and it should work:
如果要保留选项卡,请在 EOF 中添加破折号:
从:
到:
add a dash to EOF if you want to keep the tabs:
from:
to:
https://github.com/koalaman/shellcheck/wiki/SC1039
https://github.com/koalaman/shellcheck/wiki/SC1039
If-Else 内的
EOL EOL 语法可以是这种类型
EOL inside If-Else
Syntax of EOL can be this type