A script written in the shell reports an error during execution: syntax error: unexpected end of file!
This error occurs for two reasons:
The first:
If you are using the == windows system to write the script ==, then there may be different types of fileformat! It may be fileformat=dos, then you need to change the format to unix, using method:
vim xx.sh
esc > : > set ff=unix > enter > end of file
save and exit
The second type:
If you write a shell script with ==Linux system==, in the command mode of vim, you can see that the fileformat type is unix by executing: set ff, then congratulations, there is a syntax error in your shell script, you can Use the dichotomy method to check for errors one by one, specifically, comment a part, leave a part, and then execute sh -n script name to check the error until you know where the error is!