execvp() ls no such file or directory
<p>I am writing a shell emulator where if the user types "lsh ls" I would run the command <code>ls</code> and ignore the "lsh" that was input by the user. So I am using the readline library to get the input, and then parsing the line. Then I am using fork() and execvp() to run the ls command. However, When I type <code>lsh ls</code> I get the following output: </p>

<pre><code>lsh: ls: No such file or directory
</code></pre>

<p>Here is my code. I think it's treating ls as a file to search, but I don't get why it is doing this.</p>

<pre><code>int main(){
  pid_t id;
  char* line;
  char **args;
  while(1){
    line = readline("shell: &gt; ");
    if(strcmp(line,"exit") == 0){
        break;
    }
    args = parse(line);
    if(strcmp(args[0],"lsh") == 0){
        id = fork();
        if (id == 0){
            if(execvp(args[1],args) &lt; 0){
                perro("no such command");
            }
        }
        if(id &gt; 0){
            printf("I am the parent process, id %d\n",getppid());
        }
    }   
    free(line);
  }
}
</code></pre>

<p>Here is the function which parses the line. </p>

<pre><code>#define LSH_TOK_BUFSIZE 64
#define LSH_TOK_DELIM " \t\r\n\a"
char **parse(char *line){
   int bufsize = LSH_TOK_BUFSIZE, position = 0;
   char **tokens = malloc(bufsize * sizeof(char*));
   char *token;
   if (!tokens) {
    fprintf(stderr, "lsh: allocation error\n");
        exit(EXIT_FAILURE);
   }

  token = strtok(line, " \n");
  while (token != NULL) {
    tokens[position] = token;
    position++;

  if (position &gt;= bufsize) {
    bufsize += LSH_TOK_BUFSIZE;
    tokens = realloc(tokens, bufsize * sizeof(char*));
  if (!tokens) {
    fprintf(stderr, "lsh: allocation error\n");
    exit(EXIT_FAILURE);
  }
  }

  token = strtok(NULL, LSH_TOK_DELIM);
  }
  tokens[position] = NULL;
  return tokens;
  free(tokens);
}
</code></pre>