Sometimes we execute an SH file under Linux and will error "SYNTAX error:unexpected END of File", which is mainly caused by the change of working system environment.
If the original script is under Windows, write using the sublime editor. Transfer shell scripts to Linux: Using the command bash-x script check syntax always comes with an error syntax error:unexpected end of file.
cause : When a DOS file is transferred to a UNIX system, it will have a ^m at the end of each line, when Vim is used, when you view the following command: Cat-a SCRIPT
Workaround
Method One:
Windows DOS text file is based on \ r \ n As a break mark, expressed as 16 binary is 0D 0 A. The text file under Unix is marked with \ n as a break mark, which means that the 16 binary is 0 a. So when you write script uploads on Windows Linux execution, you need to vim your files, and then press ESC: Set Fileformat=unix, then: Wq save.
Method Two:
Use the command Dos2unix command to format script script
Open the command line to the file directory, with Dos2unix xxx.sh. XXX stands for file name
Dos2unix is a powerful Linux command, which can be used for reference:Dos2unix command
"Syntax error:unexpected end of File" occurs under Linux execution sh