当被问到时,如何在 bash 脚本中自动点击 Enter?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22387763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to automatically hit Enter in bash script when asked?
提问by Ooker
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
回答by Thomas Orozco
You're supposed to pipe the \n
into the command that's going to be receiving it (otherwise it won't ever see it!):
你应该通过管道\n
输入将要接收它的命令(否则它永远不会看到它!):
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:
现在,正确的解决方案是改用-y
标志:
sudo add-apt-repository -y ppa:danielrichter2007/grub-customizer
sudo apt-get install -y grub-customizer