Linux Shell-syntax error near unexpected token error

Source: Internet
Author: User

After you write a Linux shell script under Windows with Notepad, execute the syntax error near unexpected token errors

Problem principle:
Online search for a long time, find the reason, the original is the problem of return, each system of the return line character is not the same.

The window system's Notepad return is CR and LF
Linux system Notepad enter is LF
Mac System Notepad Enter is CR

Writing programs under Windows Linux executes it doesn't know what CR is. So there will be syntax error near unexpected token errors.
All characters in the text can be viewed in a Linux environment by Vi-b

Workaround:
1:vi Editor Workaround
Just remove the return line CR (^m display in vi-b) in the Linux environment.
Here CR is not sure is ^v or ^m, under Linux can not directly match CR (in Vi-b is ^m display).
So to use or match:%s/[^v|^m]$//g to match the CR (in Vi-b is the ^m display), followed by the text is the return line under Linux.

2: Notepad workaround
It seems that Windows comes with Notepad and WordPad can't convert text format, so it doesn't solve the problem.
I am using the notepad++ text editor. You can convert to UNIX format in edit->eol conversion->.

Linux Shell-syntax error near unexpected token error

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.