因此,我有一个运行sudo apt-get upgrade并自动更新的小脚本(即使我是否要升级也可以回答),但是当我通过./sync.sh
运行该脚本时,甚至会提示我输入密码我在脚本中声明了它。
有人知道发生了什么吗?
sync.sh
#Colors
green=$(tput setaf 2)
normal=$(tput sgr0)
clear
echo password | yes | sudo -S apt-get upgrade
echo "${green}-------- APT-GET UPGRADE DONE --------${normal}"
echo password | yes | sudo -S apt-get update
echo "${green}-------- APT-GET UPDATE DONE ---------${normal}"
输出如下:
Sorry, try again.
Sorry, try again.
Sorry, try again.
sudo: 3 incorrect password attempts
-------- APT-GET UPGRADE DONE --------
Sorry, try again.
Sorry, try again.
Sorry, try again.
sudo: 3 incorrect password attempts
-------- APT-GET UPDATE DONE --------
答案 0 :(得分:0)
问题可能在于echo password | yes
永远返回
y
y
y
尝试使用xargs
:
echo password | xargs yes
或仅yes
,不带管道
yes password