Shell syntax error: unexpected end of file error message

Source: Internet
Author: User
Shell syntax error: unexpected end of file error message
if [ -n "$1" ]then  echo "111"else  echo "222"fiexit 0

Execute sh my. Sh par and prompt syntax error: unexpected end of file. Why?

Text editing is a file written in notepad in windows and runs in the cygwin simulated Linux environment.

Solution:

This error is caused by the differences in file formats in DOS and Linux.

The text file in DOS uses \ r \ n as the line break Mark, which indicates that the hexadecimal format is 0d 0a. The UNIX text file uses \ n as the line break sign, which indicates that the hexadecimal format is 0a.

In Windows, two line breaks are used: Carriage Return \ r, line feed \ n,In Linux, you only need one \ n symbol..]

In Linux, when a text file in DOS format is opened with a lower version of VI, ^ m is displayed at the end of the line. Of course, it may not be visible, but in VI, the file format is displayed below. "m.txt" [dos] 8l, 72c indicates a DOS file format.

Solution:

Use the following command to set the file format to Unix to solve the preceding error.

vi M.txt:set fileformat=unix:wq

 

Reference:

Http://hi.baidu.com/hajj1987/blog/item/23339d314e163b275bb5f5ad.html

Section:

 

Http://wenku.baidu.com/view/4c1e950703d8ce2f00662398.html

 

Shell syntax error: unexpected end of file error message

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.