linux之粘贴代码或者注释时,被强制都改为注释的解决办法
直接通过vim打开脚本,然后粘贴进去后,发现,内容全部乱序,如有注释也会被之后改成注释,故此可通过以下方法:
sudo cat > /tmp/test.py <<eof
import os,sys
import pexpect
for line in open('fstab'):
str1 = line.split(' ')
ext4_name = str1[0]
ext4_file = str1[1]
# print(line)
print(f'------{ext4_name} {ext4_file}--------')
print(ext4_name)
print(ext4_file)
process = pexpect.spawn(f'sudo mkfs.ext4 {ext4_name}')
process.expect('anyway? (y,N)')
process.sendline('y')
process.expect('~$')
process.sendline(f'sudo mount {ext4_name} {ext4_file} ')
while process.expect('mount(2) system call failed: Structure needs cleaning.'):
process = pexpect.spawn(f'sudo mkfs.ext4 {ext4_name}')
process.expect('anyway? (y,N)')
process.sendline('y')
process.expect('~$')
process.sendline(f'sudo mount {ext4_name} {ext4_file} ')
eof
|