A method for Shell to solve syntax error problem

Source: Internet
Author: User
If there is a possibility of a "^m" symbol in the end of a shell script that uses Windows editing

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.

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.