I have been reading a ton about bash scripts and program testing but I am still unable to make this code work.
Basically it is a simple program that asks the user for either of
int process_input(Map *game)
char ch = getchar();
char a = getchar(); //eat enter
int damage = rand() % 4;
printf("You can go:\n");
printf("Whats next?", ch);
./ex17 echo 'w'
You can feed input into a program from bash using any of these mechanisms:
For a simple one-line string, you can use a 'here-string':
For multiple lines, you can use a "here-document":
./ex17 <<'EOF' w second line of input more input EOF
Or you can move those out of the script and into a separate file:
More generally, you can run a command that generates as its output the desired input to your program, and connect them together with a "pipe". For instance, the above could also be written:
cat filename | ./ex17
That's more general because you can replace
cat with any sort of program, which can do all sorts of computation to determine what it outputs instead of just dumping the contents of a static file.
But what you can't easily do from bash is drive input and read output and make decisions about what to send as the next input. For that, you should look at expect. An expect script would look something like this:
#!/usr/bin/env expect spawn ./ex17 expect ">" send "w\n" expect "Whats next?" send "next line here\n" # turn it back over to interactive user interact