I've created a really simple bash script that runs a few commands. one of these commands needs user input during runtime. i.e it asks the user "do you want to blah blah blah?", I want to simply send an enter keypress to this so that the script will be completely automated.
我创建了一个非常简单的bash脚本,它运行一些命令。其中一个命令在运行时需要用户输入。我。它会问用户“你想说什么?”,我只想向它发送一个enter keypress,以便脚本将完全自动化。
I won't have to wait for the input or anything during runtime, its enough to just send the keypress and the input buffer will handle the rest.
在运行时,我不需要等待输入或任何东西,它只需要发送按键和输入缓冲区就可以处理剩下的部分。
5 个解决方案
#1
84
echo -ne '\n' | <yourfinecommandhere>
or taking advantage of the implicit newline that echo generates (thanks Marcin)
或者利用echo生成的隐式换行(谢谢Marcin)
echo | <yourfinecommandhere>
#2
27
You might find the yes
command useful.
您可能会发现yes命令很有用。
See man yes
看到人是的
#3
16
Here is sample usage using expect
:
这里是使用expect的示例用法:
#!/usr/bin/expect
set timeout 360
spawn my_command # Replace with your command.
expect "Do you want to continue?" { send "\r" }
Check: man expect
for further information.
检查:期待进一步的信息。
#1
84
echo -ne '\n' | <yourfinecommandhere>
or taking advantage of the implicit newline that echo generates (thanks Marcin)
或者利用echo生成的隐式换行(谢谢Marcin)
echo | <yourfinecommandhere>
#2
27
You might find the yes
command useful.
您可能会发现yes命令很有用。
See man yes
看到人是的
#3
16
Here is sample usage using expect
:
这里是使用expect的示例用法:
#!/usr/bin/expect
set timeout 360
spawn my_command # Replace with your command.
expect "Do you want to continue?" { send "\r" }
Check: man expect
for further information.
检查:期待进一步的信息。