Heredoc中Expect命令的用法 [英] Usage of expect command within a heredoc

查看:90
本文介绍了Heredoc中Expect命令的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下将功能添加到bash配置文件的微小期望脚本:

For the following tiny expect script for which a function was added to the bash profile:

chai() {
    expect <<- EOF
    spawn ssh myuser@myserver
    expect ': $'
    send 'mypassword\r'
    EOF
}

我们得到:

bash: /etc/profile: line 409: syntax error: unexpected end of file

该脚本有什么问题?

推荐答案

我通常希望

I would normally expect the heredoc terminator (EOF) to be at the start of the line e.g.

chai() {
    expect <<- EOF
    spawn ssh myuser@myserver
    expect ': $'
    send 'mypassword\r'
EOF
}

我看到您使用的是<<-,并且来自链接的文档:

I see you're using <<- and from the linked doc:

用于标记此处文档限制字符串(<< -LimitString)的-选项 禁止输出中的前导制表符(但不包括空格).这可能是 有助于使脚本更具可读性.

The - option to mark a here document limit string (<<-LimitString) suppresses leading tabs (but not spaces) in the output. This may be useful in making a script more readable.

,因此您应该检查脚本以查看命令前是否有TAB. EOF遵循相同的规则.

so you should check the script to see if you have a TAB preceding your commands. The EOF is subject to the same rules.

cat <<-ENDOFMESSAGE
    This is line 1 of the message.
    This is line 2 of the message.
    This is line 3 of the message.
    This is line 4 of the message.
    This is the last line of the message.
ENDOFMESSAGE
# The output of the script will be flush left.
# Leading tab in each line will not show.

这篇关于Heredoc中Expect命令的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆