Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass input to interactive command line program in bash [duplicate]

I have a program that has its own prompt

example_program>

I need to run a series of command via this program

example_program> command_A
example_program> command B
Please enter input: [input_here]
example_program> command C

I can send commands A,B,C via the following line in a shell script:

(echo "command_C" && cat) | (echo "command_B" && cat) | (echo "command_A" && cat ) | example_program

How can I enter in the input needed and am prompted for after command B ([input_here])?

I do not have access to send or expect.

like image 233
Tim Avatar asked Dec 01 '14 18:12

Tim


People also ask

How do I give input to a program that I am calling inside bash script?

You can do either a C code or a Bash script, not a mixed one. Use scanf() for reading from keyboard (it stops reading when you hit ENTER) and complete this code in C language.

How do I pass an environment variable in bash script?

Environment Variables Bash scripts can also be passed with the arguments in the form of environment variables. This can be done in either of the following ways: Specifying the variable value before the script execution command. Exporting the variable and then executing the script.


1 Answers

I'm guessing this will work, but it's only a guess since we don't know how your program is reading the responses: use a here-doc, and put the input for command B after invoking command B

example_program <<'END'
command_A
command B
input_here
command C
END
like image 102
glenn jackman Avatar answered Sep 20 '22 00:09

glenn jackman