Shell script error example

Source: Internet
Author: User

A shell script error often occurs when writing a script: Write it in windows and copy it to execute it. However, an error is reported when you test it, the error is amazing. for example, my for loop statement encountered a syntax error near unexpected token do error. I carefully read the shell script I wrote several times and found that there was no error, the last possible cause is that the line break www.2cto.com is caused by the dos format "\ r \ n". You can use the cat-v file name to check whether the line break is true, if this is the preceding, the line ends with ^ m and needs to be converted to "\ n" in linux/unix format. The specific conversion method is to convert the line break. You can use the sed command to process the file, the command is as follows: sed's/\ r // G' original File> in the parameters of the converted file www.2cto.com sed ", it indicates that the reference parameter is determined. The value of this parameter cannot be explained by shell, s indicates replacement. The replacement is followed by replacement. The content, followed by // indicates that the replaced content is empty. EditPlus or UltraEdit is recommended. When using these text editing tools, you can select the type of the saved text encoding when saving the content, for example, select a UNIX line break. I prefer the join lines function of EditPlus to convert the values of multiple rows into a logical row, which is easy to write to shell scripts as cyclic variables.

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.