shell脚本运行中自动输入密码

需求:有一个shell脚本autoload.sh 需要运行过程中自动输入密码,而不用手工。
解决方法:
使用管道,并使用-S参数来指定密码输入方式:

echo 'mindthink' | sudo -S ./autoload.sh

其中 mindthink 为密码。

参考链接

打赏作者