title: How do I provide input to a C program from bash?
body: <p>I have been reading a ton about bash scripts and program testing but I am still unable to make this code work. </p>
  
  <p>Basically it is a simple program that asks the user for either of <code>north</code> <code>east</code> <code>south</code> or <code>west</code>. I start the program then it immediately asks for input. I just can not get the bash script to give it any input. I tried using <code>echo</code> and <code>expect</code>.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Here is the function used to get the players input:</p>
  
  <pre><code>int process_input(Map *game)
  {
      printf("\n&gt; ");
  
      char ch = getchar();
      char a = getchar(); //eat enter
  
      int damage = rand() % 4;
  
      switch(ch) {
  
          case -1:
              printf("you suck\n");
              return 0;
              break;
          case 'n':
              game-&gt;proto.move(game, NORTH);
              break;
          case 's':
              game-&gt;_(move)(game, SOUTH);
              break;
          case 'e':
              game-&gt;_(move)(game, EAST);
              break;
          case 'w':
              game-&gt;_(move)(game, WEST);
              break;
          case 'a':
              game-&gt;_(attack)(game, damage);
              break;
          case 'l':
                      printf("You can go:\n");
                      if(game-&gt;location-&gt;north) printf("NORTH\n");
                      if(game-&gt;location-&gt;south) printf("SOUTH\n");
                      if(game-&gt;location-&gt;east) printf("EAST\n");
                  if(game-&gt;location-&gt;west) printf("WEST\n");
                      break;
          default:
              printf("Whats next?", ch);
          }
          return 1;
  }
  </code></pre>
  
  <p>And here is the attempt at a bash script:</p>
  
  <pre><code>   #!/bin/bash
      /Desktop/c
      ./ex17 echo 'w'
  </code></pre>