Linux Shell pin This newspaper wrong "syntax error near unexpected token '" solution

Source: Internet
Author: User
Tags knowledge base

Today wrote a shell script, the old error check the basic syntax and did not find errors. Later after the settlement of Baidu, and now summarized as follows.

error phenomenon : Execute shell script, old error "syntax error near unexpected token '"

workaround : vim-b example.sh Open the file, found that the file at the end of each line of a ^m, the problem in the use of Vim example.sh view is invisible, only by error to determine the use of vim-b to find the problem.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8D/7C/wKioL1idxdbzc0yuAAATvQhmgZ0815.png "title=" Capture 1. PNG "alt=" Wkiol1idxdbzc0yuaaatvqhmgz0815.png "/>650) this.width=650; src=" https://s1.51cto.com/wyfs02/M02/8D/ 7c/wkiol1idxkdhtwrcaaajrgbrjzk867.png "title=" Capture 2. PNG "alt=" Wkiol1idxkdhtwrcaaajrgbrjzk867.png "/>

Because MS-DOS and windows are carriage return + newline to represent line breaks, so under Linux with Vim to see the code written in the VC under Windows, the "^m" symbol after the end of the line, indicating the character.

To solve this problem in vim, it is easy to use the Replace function in Vim to kill "^m" and type the following command line:

1) vi-b setup.sh

2) in the command edit line < just: Press ESC and 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.

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

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

Error reason : When writing a script, the script was edited using UltraEdit, and then there was the version of the WinDOS computer, which was then transferred to the Linux system for execution. It is possible that the default DOS format is enabled when storing text.




This article is from the "Small Knowledge Base" blog, make sure to keep this source http://babyhanggege.blog.51cto.com/11741640/1896833

Linux Shell pin This newspaper wrong "syntax error near unexpected token '" solution

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.