title: Shell seems to recognize commands but doesn't execute them
body: <p>I am trying to implement basic command execution in a shell program for the unix-like xv6 OS. The part of the shell code that I am editing is the runcmd function where I am using the execvp command to execute the commands used in the terminal. The program compiles without errors when I compile it but nothing happens when I try to type a command on the command line. I've read the <a href="http://man7.org/linux/man-pages/man3/exec.3.html" rel="nofollow noreferrer">man pages</a> for the exec command, but I still don't really understand the proper way in which these arguments need to passed in the exec() command or when to use which version of exec() as I'm still very new to OS programming.</p>
  <p>What haven't I implemented here that needs to be added in order for commands to be executed? I have the code for the runcmd function below:</p>
  <h2>EDIT:</h2>
  <p>I just added more exec statements with the paths to the binary for each command; however, only the first exec command works (which is cd in this case). When I use any other command, the command line executes it as if it is CD. How do I get it to work for multiple commands?</p>
  <pre><code>struct cmd {
    int type;          //  ' ' (exec), | (pipe), '&lt;' or '&gt;' for redirection
  };
  struct
   execcmd {
    int type;              // ' '
    char *argv[MAXARGS];   // arguments to the command to be exec-ed
  };
  
  // Execute cmd.  Never returns.
  void
  runcmd(struct cmd *cmd)
  {
    int p[2], r;
    struct execcmd *ecmd;
    struct pipecmd *pcmd;
    struct redircmd *rcmd;
  
    if(cmd == 0)
      exit(0);
    
    switch(cmd-&gt;type){
    default:
      fprintf(stderr, &quot;unknown runcmd\n&quot;);
      exit(-1);
  
    case ' ':
      ecmd = (struct execcmd*)cmd;
      
      if(ecmd-&gt;argv[0] == 0)
        exit(0);
      //fprintf(stderr, &quot;exec not implemented\n&quot;);
       execvp(&quot;/bin/cd&quot; , ecmd-&gt;argv );
       execvp(&quot;/bin/grep&quot; , ecmd-&gt;argv );
       execvp(&quot;/bin/echo&quot; , ecmd-&gt;argv );
       execvp(&quot;/bin/cat&quot; , ecmd-&gt;argv );
       execvp(&quot;/bin/ls&quot; , ecmd-&gt;argv );
      break;
  
    case '&gt;':
    case '&lt;':
      rcmd = (struct redircmd*)cmd;
      //fprintf(stderr, &quot;redir not implemented\n&quot;);
      execvp(&quot;/bin&quot; , ecmd-&gt;argv );
      runcmd(rcmd-&gt;cmd);
      break;
  
    case '|':
      pcmd = (struct pipecmd*)cmd;
      fprintf(stderr, &quot;pipe not implemented\n&quot;);
      int execl(const char *path, const char *arg, ...);
      break;
    }    
    exit(0);
  }
  </code></pre>