In Linux, the case reports syntaxerrornearunexpectedtoken 'in.

Source: Internet
Author: User
In Linux, case errors are reported: syntaxerrornearunexpectedtoken 'in -- general Linux technology-Linux programming and kernel information. For more information, see the following. I originally wrote an sh script to install jdk and tomcat in linux, and it was running very well. After that, it was stored in windows for a period of time,

Now we get the linux execution, but the error "syntax error near unexpected token 'in" is reported during the running ".

Has it deteriorated for a while? But it is indeed deteriorating. In windows, I once opened this document, resulting in the format of the document in dos. (Just like food ). The operation can be as follows.

To ensure correct syntax:

1. Create a New a. sh file. Write several lines of scripts to save.

2. Use the command vi-B a. sh to view the same content as that shown in vi a. sh.

3. Now compare my original documents. It is found that each row of scripts has an additional ^ M.

Then we need to figure out what this ^ M is?

Long ago... the old-fashioned typewriter uses two characters to start a new line. One character moves the slide Frame back to the first place (called carriage return, , The ASCII code is 0D), and the other character moves a line (called line feed, , ASCII code is 0A ). After the advent of computers, memory was once very expensive. Some people think that there is no need to use two characters to represent the end of the line. UNIX developers decide that they can use a single character to indicate the end of a line. Linux follows Unix and . Apple developers have defined . Those guys who develop MS-DOS and Windows decide to keep old-fashioned .

Because MS-DOS and Windows are carriage return + line feed to represent the line feed, so in Linux with Vim to view the code written with VC in Windows, line after the "^ M" symbol, indicates the operator.

To solve this problem in Vim, you can use the replacement function in Vim to kill "^ M" and enter the following command line to replace:

1) vi-B setup. sh

2) In the command editing line <就是: 按esc键 然后shift+:冒号> Input: % s/^ M/g

Note: The "^ M" character in the preceding command line is generated by the "Ctrl + v" and "Ctrl + M" keys instead of "^" and "M.

After replacement, save and run the command. Of course, there are other replacement methods, such:

A. Some linux versions include the dos2unix program, which can be used to remove ^ M.

B. cat filename1 | tr-d "\ r"> remove the newfile ^ M to generate a new file, and use the sed command to generate a new file. All commands that can be replaced can be used to generate a new file.

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.