One-time digging and filling of the Linux sh script in the Windows environment

     When researching Docker cluster and installation recently, several machines need to be prepared. So in order to save time, I plan to copy VM machines in batches, and then use sh script commands to modify basic configuration information such as machine name and IP.

Specific operation: I use Notepad++ to edit the following script in the Windows environment, and save the encoding format as UTF-8 without encoding BOM.

But the test found that linux will automatically write the \r at the end of the command line to the execution command.

 

 

 

First, the failure process, as follows

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

 

Then, we tried to find the ifcfg-eno01 file we just created, but it was prompted that it could not be found. The reason is that Windows automatically adds \r to each line of commands, and Linux regards it as part of the file name.

 

 

 Second, the successful process, as follows

 First, in vim mode, execute :set ff=unix to delete the \r automatically added to the end of each line of the sh script in the windows environment.

 

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

 


To sum up, any tool to write sh script files in the windows environment must remember to set ff=unix to remove the extra \r at the end of each line        before executing the sh script after uploading to the linux environment .

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325310174&siteId=291194637