I know how send a command as a input in a program like this:

echo toto | ./my_prog

And with process substitution + redirection:

r < <(echo toto)

But how to do this if I want to input a second or a third input?

For example, I have a program that ask my username first and after this it ask me others informations like a number phone or whatever in different input.

3 Answers 3


I would suggest a here document

./my_proc << END_OF_INPUTS
phone number
  • This is the best answer. Sep 13, 2019 at 19:52

Use { and } to collect the output of multiple programs. For instance, { echo one; echo two; } |program. Leave a space after { and before } and ensure there is a semicolon after the last command within the braces.


You can use printf and a pipe too

printf "%s\n" "username" "number phone" "whatever" | ./my_prog
  • I can use python too like this: python -c 'print "toto\x0Atutu\x0A\x0A5\x0A"' | ./my_prog
    – salt
    Mar 1, 2018 at 21:29
  • 1
    Seems a bit of overkill to spawn python just for this. printf is a shell builtin. Mar 1, 2018 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.