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