title: own shell in C using execv
body: <p>I am trying to build my own shell in C as part of a class project. We are required to use execv and implement our own path. For better understanding here is the question:</p>
  <blockquote>
  <p>The list of paths is empty by default, but may grow to any arbitrary size. You should implement a built-in command to control this variable:</p>
  <pre><code>path [+|- /some/dir]
  </code></pre>
  <ul>
  <li><p><code>path</code> (without arguments) displays all the entries in the list separated by colons, e.g. &quot;/bin:/usr/bin&quot;.</p>
  </li>
  <li><p><code>path + /some/dir</code> appends the given pathname to the path list.</p>
  </li>
  <li><p><code>path - /some/dir</code> removes the given pathname from the path list.</p>
  </li>
  </ul>
  </blockquote>
  <p>I have misread the assignment and used execvp so far. Please can you shed some light on how to create my own path variable, and for each command executed search the directory it is in and add it to the path? Or is there any simple shell written using execv I can take a look at?</p>
  <p>I saw <a href="http://linuxgazette.net/111/ramankutty.html" rel="nofollow noreferrer">http://linuxgazette.net/111/ramankutty.html</a>, but I found the search a little too complex, and he uses execve.</p>
  <p>so far i have char *mypath variable which is null initially. but the user can add or remove using path + some/dir or path - /some/dir. syntax for execv is execv(&quot;/some/dir&quot;, argv) how do i search my path for the executable and pass it to execv....for example mypath=/bin/ls ; when i pass execv(mypath, argv) it does not work...so how do i pass the path to execv?</p>