"Syntax error:unexpected end of File" occurs under Linux execution sh

Source: Internet
Author: User
Tags sublime editor

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

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.