Reputation: 2289
I'm writing a shell and I want to use execv() and search for the right directory through the $PATH
environment variable (Yes, I know I can use execvp()
and just pass the name of the file to it).
What I'm thinking about doing is getting a string from getenv("PATH")
, breaking it down to separate paths then trying each one. But I was wondering if there is an easier way to do it?
I guess the question is: how does execvp()
search for the right path?
Thanks!
Upvotes: 2
Views: 1969
Reputation: 993045
What you described is exactly how execvp()
searches the PATH. I don't think there's much point in reimplementing this yourself.
Upvotes: 5