A dig pit and pits for Linux sh scripts written in Windows environment

Source: Internet
Author: User

Recently, when researching Docker clusters and installations, several machines need to be prepared. So I want to save time, I intend to bulk copy VM machine, and then use the SH script command to perform machine name and IP and other basic configuration information modification.

What to do: in the Windows environment, I edited the following script with notepad++, and saved the encoded format as UTF-8 no-coded BOM.

However, the test found that Linux automatically writes the \ r of the end of the command line to the execution command.

One, the failure process, as follows

>> Sh-x/opt/command/batch_modify_servername_all.sh

Then, we tried to find the ifcfg-eno01 file that we just created, but we couldn't find it because Windows automatically added a \ r to each line of the command, and Linux turned him into a part of the file name.

Second, the success process, as follows

First, in vim mode, execute: Set Ff=unix, to remove the Windows environment to the SH script each line end automatically added \ r.

Then, we try to find the ifcfg-eno01 file that we just created, this time we can find it, as follows

Summary, in the Windows environment any tool to write SH script files, after uploading to the Linux environment after the SH script must remember to set Ff=unix
Remove the redundant \ R at the end of each line.

Finally, attach the code: (If you have help, please help me to praise, you support is also my motivation to write, thank you)

https://files.cnblogs.com/files/itshare/batch_modify_servername_all.sh

A dig pit and pits for Linux sh scripts written in Windows environment

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.