Usage of expect command within a heredoc

后端 未结 1 1669
执笔经年
执笔经年 2021-01-19 09:15

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

chai() {
    expect <<- EOF
    spawn ssh myuser@myserver
             


        
相关标签:
1条回答
  • 2021-01-19 09:58

    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:

    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.

    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.
    
    0 讨论(0)
提交回复
热议问题