Hey guys,
So im working on this project which is create a shell in C using fork() and execve() commands in POSIX.
The main things is a read_command() functions and a main which just has a while loop with fork and execve with an if statement that takes out the waitpid() command if the user types <command> & which means they want to run it in the background.
Now what i am trying to do is make it so instead of having to type a command such as /bin/ls or /usr/bin/xeyes to be able to jsut type "ls" or "xeyes" and so on. Is there anyways that i can get the system environment paths?
or can someone gimme a hint as to how to go about this problem?
Note: i am not asking for you to do it nor am i asking for u to give me the code

i know but we cant use it i knwo that exec has a whole family of functions but we must use the execve(command,parameters,environ).

You mean like
char *p = getenv("PATH");

Then you parse that string, looking for directories, then testing each in turn?

something like that yest but could you explain "PATH" is (is it something i choose like /bin/ or is it like an environment path with many
PATH=/usr/bin/ ; /bin/ : and so on.
also one i parse it and get a path for example /bin/ and the command is "ls" how would i put that together? creating another array of characters and puttign the two together or is there a simplar way.
Thanks for all your help salem

What do you mean "explain PATH".
Just write some code, print it out, and learn.

Given the scope of the original problem, a bit of simple string handling should not be an issue here.
You already seem to know the answer, so try it.

This article has been dead for over six months. Start a new discussion instead.