here-document gives 'unexpected end of file' error

后端 未结 7 2569
生来不讨喜
生来不讨喜 2020-11-22 04:42

I need my script to send an email from terminal. Based on what I\'ve seen here and many other places online, I formatted it like this:



        
7条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 05:37

    The line that starts or ends the here-doc probably has some non-printable or whitespace characters (for example, carriage return) which means that the second "EOF" does not match the first, and doesn't end the here-doc like it should. This is a very common error, and difficult to detect with just a text editor. You can make non-printable characters visible for example with cat:

    cat -A myfile.sh
    

    Once you see the output from cat -A the solution will be obvious: remove the offending characters.

提交回复
热议问题