title: Implementing a simple shell
body: <p>Making a simple -type shell, using fork and execvp functions to run the commands from the stdin line. </p>
  
  <p>However, things like <code>ls</code> work, but not <code>ls -all -S</code>.
  It will execute <code>ls</code>, but nothing will be printed for <code>ls -all</code></p>
  
  <p>The only idea I can come up with is that there is a "\n" somewhere in the command, but I don't know how to get it out or even where it is....</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  //Libs ^^^^ Defs vvvvvvvv
  #define comlen 4096                     //Max command length
  #define comarg 32             //Max argument length
  
  int main(int argc, char *argv[]) 
  {
    char buff; //command buffer
      char* comand[comlen];
      int i;
    do
    {
          i = 0;
      printf("simsh: ");
  
          char* whtspc = strtok (fgets(&amp;buff, comlen, stdin)," ");  //get input and tokenize
          printf("[%lu]   ::   %s------------\nEND OF BUFF TEST\n", strlen(&amp;buff), &amp;buff);
  
      while (whtspc != NULL)
      {
            comand[i]=(char*)malloc((sizeof(char)*strlen(whtspc))); //alloctie mem for commands
            strncpy(comand[i], whtspc, strlen(whtspc)-1);                     //coppy comand token to array index i
            whtspc = strtok (NULL, " ");                                                      //grab next token
              i++;                                                                                                        //incriment
              /*trying to change new line character to NULL so that commands can be passed properly*/
  //          if (comand[strlen(comand[i]) - 1] == "\n") 
  //          {
  //              comand[strlen(comand[i]) - 1] = '\0';
  //          }
              //breka out incase index oversteps
              if (i == 4096)
                  break;
      }
          //last entry in command should be null
          comand[i] = NULL;
          //fork to run in background
          pid_t pid = fork();
  
          if (pid == 0)
          {
              //testing and pass comands to execvp
              printf("START OF COMAND TEST\n!!!!!!!!!%s!!!!!!!!!!!!!!!!\n %lu\nEND OF COMAND TEST\n\n",comand[1], strlen(comand[0]));
              execvp(comand[0], &amp;comand);
          }
  
          else
          {
              //parent wait on child.
              waitpid(pid, &amp;i, WUNTRACED | WCONTINUED);
          }
      }
      while(1);
  
    return 0;
  }
  </code></pre>
  
  <p>Any help would be welcomed.</p>
  
  <p>If it helps at all , here is the terminal output of the code::</p>
  
  <pre><code>simsh: ls
  [3]   ::   ls
  ------------
  END OF BUFF TEST
  START OF COMAND TEST
  !!!!!!!!!(null)!!!!!!!!!!!!!!!!
   2
  END OF COMAND TEST
  
  chop_line.c  chop_line.h  list.c  list.h  Makefile  Makefile~  One  simsh1  simsh1.c  simsh1.c~
  simsh: ls -all
  [2]   ::   ls------------
  END OF BUFF TEST
  START OF COMAND TEST
  !!!!!!!!!-all!!!!!!!!!!!!!!!!
   1
  END OF COMAND TEST
  
  simsh: echo
  [5]   ::   echo
  ------------
  END OF BUFF TEST
  START OF COMAND TEST
  !!!!!!!!!(null)!!!!!!!!!!!!!!!!
   4
  END OF COMAND TEST
  
  
  simsh: echo all
  [4]   ::   echo------------
  END OF BUFF TEST
  START OF COMAND TEST
  !!!!!!!!!all!!!!!!!!!!!!!!!!
   3
  END OF COMAND TEST
  
  simsh: echo echo
  [4]   ::   echo------------
  END OF BUFF TEST
  START OF COMAND TEST
  !!!!!!!!!echo!!!!!!!!!!!!!!!!
   3
  END OF COMAND TEST
  </code></pre>