Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a C program in which I use scanf to get user input. Now, I would like to make a .sh script that automatically test this program with pre-defined user input, but I'm not sure how I can send the input every time the program needs it.

share|improve this question
up vote 8 down vote accepted
./a.out << EOF
first line of input
second line of input
share|improve this answer
This works fine! Thank you! – Valentin Radu Sep 30 '11 at 12:26
@ValentinRadu If you want to read more about this feature, it's called a heredoc or here-document. – Gilles Sep 30 '11 at 23:19
Cool, I see that you can use any kind of "tags" not only EOF. Thanks! – Valentin Radu Oct 1 '11 at 7:43
Yes, but EOF is the convention, unless you think your input might have have that string in it. – Paul Tomblin Oct 1 '11 at 12:22

If you need to have an automated conversation with your program (i.e. want to interpret the output as well), take a look at expect. This is a tcl based tool for automating interactive sessions. It might give you what you want.

share|improve this answer
Seems cool, but it's more than what I need:) – Valentin Radu Sep 30 '11 at 12:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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