I need to run a command and answer a couple of prompts the command asks. Unfortunately I can't input the prompts manually so I'm looking for a way to do that automatically.
I can't install an external package like expect
or yes
, I also can't move my commands into a .sh file.
I've managed to pass one answer like this:
echo 'response' | command
But I can't figure out how to send multiple prompts for the same command.
Is this possible?
EDIT:
The command is:
certbot certonly --apache
Using a loop might be helpful.
With arrays:
Or as @steeldriver suggested:
Lets say command is a script asking for inputs:
The output would be: 3
yes
in first case andyes
,yes
,no
in the second one.Additionally you could try using
<< EOF
, some number of answers one by line,EOF
construction:You could also create an
answers
file:And then just pipe the file content using
cat
command: