About the error "syntax error near unexpected token '" and carriage return line wrapping

Source: Internet
Author: User

It was a simple thing to turn around because the typewriter was more interesting ...

Http://blog.csdn.net/xyp84/archive/2009/08/11/4435899.aspx

Summary:

Enter

Line Wrap

0D

0A

<CR>

<LF>

Carriage return

Line Feed

"/R"

"/n"

Win32

0D

0D 0A

Unix

0D

0A

============ the =============== of the split line

Today wrote a shell script, on their own machine running normal, to colleagues, run error syntax error near unexpected token ', left look right look at the shell script no problem, no way Google search, found a friend said very good, the contents are as follows:

Open your shell script file with command Vi-b, you will. found that each line of script ended up with an extra ^m.

Then we have to figure out what this ^m is.

Long long ago ..... An old-fashioned typewriter uses two characters to start a new line. One character moves the slider back to the first (called Carriage return, <CR>,ASCII Code is 0D), and another character moves the paper up one line (called a newline, and the <LF>,ASCII code is 0A). After the advent of computers, memory was once very expensive. Some people assume that there is no need to use two characters to indicate the end of a line. UNIX developers decide that they can use a character to represent the end of the line, Linux to follow Unix, and <LF>. Apple developers have defined the use of <CR>. The guys who developed MS-DOS and Windows decided to use the old-fashioned <CR><LF>.

Because MS-DOS and windows are carriage return + line wrapping, so in Linux with Vim to see the code written in Windows VC, after the end of the "^m" symbol, the expression is a character.

In Vim to solve this problem, it is very simple, in vim with the substitution function can kill "^m", type the following replacement command line:

1) vi-b setup.sh

2 in the command edit line < is: Press Esc key then shift+: colon > Input:%s/^m//g

Note: the "^m" character in the above command line is not "^" plus "M", but is generated by the "Ctrl + V" and "ctrl+m" keys.

After this is replaced, the save can be executed. Of course, there are other ways to replace them, such as:

A. Some Linux versions have Dos2unix programs that can be used to eliminate ^m.

B.cat filename1 | Tr-d "/R" > NewFile remove ^m to generate a new file, as well as the SED command, which can be replaced by the command can be used to new into a file.

According to the above, delete the ^mshell script to run normally, and then ask colleagues, it turns out that he has modified the program path in Windows Notepad, resulting in more than ^m each row.

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.