I have an executable program that takes if/else user inputs and I want to run it from a bash terminal in one line, i.e. without having to go through the program prompts.
Is there a way to pass echo commands?
Assuming that your program is reading data line by line, then you can do the following in bash.
{
echo "input 1"
echo "input 2"
echo "input 3"
...
echo "input n"
} | my-program
The {} creates a command group, and the outputs of the commands within that group are piped to my-program.
An alternate approach is to use a heredoc, which can be written as follows:
{
cat <<EOM
input 1
input 2
input 3
...
input n
EOM
} | my-program
Note that the EOM string to terminate the heredoc must be on a line by itself, therefore, you need to either create a command group or a subshell to ensure that the cat command doesn't send its output directly to your shell STDOUT, but instead to the pipe.