在脚本中使用sudo echo 'passward' | sudo -S cp file1 /etc/hosts
echo 'passward' | sudo -S cp file1 /etc/hosts