previous | start | next

PATH environment variable, execvp and execve

Use execvp instead of execve!

Otherwise, users of your shell will need to know the full path to execute typical commands like ls, cd, ps, etc.

The p in execvp takes only 2 parameters, but this version of exec will examine the directories in your PATH environment variable when searching for the executable file.

The execve version takes 3 parameters (execvp takes only the first 2):

  1. filename
  2. array of "command line" arguments
  3. array of environment variable=value strings

The filename can be an absolute or relative.

For an absolute filename (one that starts with "/"), the search begins at the root directory "/" and searches through all components of the path to find the executable file.

For a relative filename (doesn't start with "/"), the search begins from the current working directory.

So with execve, you would need to type the absolute path:

 /bin/ls      
   

instead of

 ls
   

to list the current directory.



previous | start | next