在所编写的脚本文件中,使用 echo "passwd" | sudo -S command
使用-S是:使得sudo从标准输入读取密码而非终端
sudo的命令选项:
Options:
-A, --askpass use a helper program for password prompting
-b, --background run command in the background
-C, --close-from=num close all file descriptors >= num
-E, --preserve-env preserve user environment when running command
-e, --edit edit files instead of running a command
-g, --group=group run command as the specified group name or ID
-H, --set-home set HOME variable to target user's home dir
-h, --help display h