[EDITED]
It can be considered as an extension to [this question][1].
echo | command
The above command can be used to supply one 'ENTER' character to the command's first input request.
How can i supply the next 'ENTER' character to the same command in its second input request.
Please comment if any other details are required.
Am giving the specific example which i want to implement.
I need to run SSH-keyGen
commmand in my shell script.
It will ask for following inputs:
- Enter the target file name
- Enter the pass phrase
- Enter the pass phrase again
How can we pass these three inputs to the command?
I tried with,
echo -ne "\n \n"| ssh-keygen //which is passing two new lines for the first input request only.
and
echo -ne "\n"|(echo -ne "\n"|ssh-keygen)// but still no positive result
Note: Am avoiding the input file name request in the above two command, just to make the things simple
The general solution is to use the
yes
command:yes
will repeatedly output the string specified on the command line with a newline appended. If you run it with an empty string as an argument, it'll output an endless string of newlines.You should take a look at expect:
How about a heredoc with 2 empty lines:
or use printf
For example, you can use either
or
The
-e
option tellsecho
to interpret escape characters.\n
is the newline (enter) character. So the first prints a newline due to\n
, and then another one sinceecho
usually appends a newline.The
-n
option tellsecho
to suppress adding an implicit newline. To get two newlines, you thus need to specify two\n
.Edit:
The problem here is that
ssh-keygen
is special. Due to security considerations, the passphrase is not read from standard input but directly from the terminal! To provide a passphrase (even an empty one) you need to use the-P
option. Since you then only need one ENTER (for the file path prompt), this command should work:(note the two
'
with no space in between: they are important!)