shell script error: "syntax error: unexpected end of file"

When the windows shell script notepad ++ to edit, copy centos to perform, given as follows:

 

Possible reasons for the error:

The reason 1: Windows is the default dos text format, line breaks  CR LF . Linux is a unix text format, line breaks  LF . Further, the line breaks the Mac text is CR .

1 to solve: the format to turn dos unix format, then the script will not execute the error.

Conversion mode 1: in the windows, bottom right notepad ++ editor document format can be edited directly, as shown:

 

 

Conversion mode 2: In Linux, open the script with vim

Use: set ff can view the file format

With: set ff = unix may set the file format unix:

 

 

 

Conversion Mode 3: In Linux, with dos2unix tool to convert:

yum -y install dos2unix

dos2unix myScript.sh

 

2 reasons: errors shell script format. A quick check with the following command if the script formatting errors:

sh -n myScript.sh

Solve 2: syntax error checking scripts, can be corrected.

=============================================================

My error reasons:

Investigation for a long time and found that the error is not due to formatting issues. But grammatical errors, as follows:

 

2019-12-25,Merry Christmas~ 

Guess you like

Origin www.cnblogs.com/iouwenbo/p/12098796.html