The most likely cause of this problem is:
Files written under Windows are uploaded to Linux execution.
I wrote the code on notepad++, and then uploaded it to Linux to execute it and report this error. Careful examination, there is no grammatical error. Surfing the Internet, found that Windows and Linux are different lines of the cause of the change.
Windows is carriage return + line Crlf;linux is just a line break LF
Cr means carriage return, enter, \R,ASCII code of 13
LF means linefeed, newline, \n,ascii code 10
In notepad++, you can view: View-show symbols-show line endings, with the following effects:
To run under Linux, you need to turn it into a Unix format file: Edit-Document Format conversion-to UNIX format with the following effect:
After that, it's no problem to upload to Linux.
or You can use Linux tools to convert files to UNIX files:Dos2unix file name
In addition, a syntax error:unexpected end of file error may also be caused by a syntax error. Use the Sh-n file name to check where syntax errors occur.
Execute Shell Foot report error: syntax error near unexpected token ' or syntax error:unexpected end of File