[英]Automate pressing enter key inside of bash script
I have a Bash script where I try to wget a repo for which I have to press enter for a very long Eula text, literally I have to manually press enter key 20+ times and then type yes.我有一个 Bash 脚本,我尝试在其中获取一个 repo,我必须按 Enter 键输入很长的 Eula 文本,实际上我必须手动按 Enter 键 20 次以上,然后键入 yes。 Can someone please help me to automate pressing enter key and at the end enter yes in bash script.
有人可以帮我自动按下回车键,最后在 bash 脚本中输入 yes。
yes "" | command
and和
echo -ne '\n' | <command>
doesn't work for me, I still have to manually press enter key.对我不起作用,我仍然必须手动按 Enter 键。
Here is the code, so when it runs wget, I need to keep pressing enter till it ask if you want to accept the license and there I enter "yes".这是代码,所以当它运行 wget 时,我需要一直按 Enter 直到它询问您是否要接受许可证,然后我输入“是”。
#!/bin/bash
pid=$(ps aux | grep xxx-server |grep -v grep | awk '{print $2}')
if [ -n "$pid" ]; then
kill $pid
echo -e "\n$pid killed -Success"
fi
# Check if the package already installed then remove it
if [ `dpkg -l | grep xxx-server | wc -l` -gt "0" ]
then
apt-get -y remove xxx-server
fi
# wget the repo using silent install
if [ "apt-cache search xxx-server" ];then
#if [ $? != 0 ] ; then
echo -e "\nremoving repo ...."
#aptitude install $i -y > /dev/null
apt-get purge xxx-server-repo-* -y > /dev/null
echo -e "\nInstalling Reop .........."
yes "" | wget -q -O - http://xxx-server.com/ | sh
fi
I don't know what are you trying to do, you'd better show us some code!我不知道你想做什么,你最好给我们看一些代码! But most probably you want to use expect:
但很可能你想使用期望:
#!/usr/bin/expect
spawn "yourscript"
for {set i 0} {$i < 20} {incr i 1} {
send "\n"
}
send "yes\n"
Even though the question is pretty old.尽管这个问题已经很老了。 This answer might help someone.
这个答案可能对某人有所帮助。
you can use this to supply input to your scripts.您可以使用它来为您的脚本提供输入。
cat <(echo "yes") | "Your_Command"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.