How to automatically hit Enter in bash script when asked?

妖精的绣舞 提交于 2021-02-07 14:50:31

问题


I know that this question is answered many times, but I still can't figure out how to do it. Maybe it's because I don't know the correct keyword to search for.

Using

echo -ne '\n' | enter

doesn't work. My code is:

#! /bin/bash
#Grub-customizer
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
echo -ne '\n' | return
sudo apt-get update
sudo apt-get install grub-customizer

回答1:


You're supposed to pipe the \n into the command that's going to be receiving it (otherwise it won't ever see it!):

echo -ne '\n' | sudo add-apt-repository ppa:danielrichter2007/grub-customizer
echo -ne '\n' | sudo apt-get install grub-customizer

Now, the right solution here would instead be to use the -y flags instead:

sudo add-apt-repository -y ppa:danielrichter2007/grub-customizer
sudo apt-get install -y grub-customizer


来源:https://stackoverflow.com/questions/22387763/how-to-automatically-hit-enter-in-bash-script-when-asked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!