find the exact path to execute???

find the exact path to execute???

Post by abdul remane cassam » Thu, 15 May 2003 05:07:18



i`m implementing a shell, i`m having problems with finding the the exact
path wich contains the commad<entered in the shell>.
how can i use the access(Path,x_ok) method ???
is there any other method i can use.
programing in c
 
 
 

find the exact path to execute???

Post by Barry Margoli » Thu, 15 May 2003 05:42:41




Quote:>i`m implementing a shell, i`m having problems with finding the the exact
>path wich contains the commad<entered in the shell>.
>how can i use the access(Path,x_ok) method ???
>is there any other method i can use.
>programing in c

If the command name contains any '/' characters, use that as the path.
Otherwise, use getenv("PATH") to get the PATH environment variable, and
append the command name to each directory in there until you find it.

But why do you think you need to use access()?  You can use execvp() and it
will automatically search the path for you.  If the user doesn't have
execute permission then it will return an error.

Note that you have to check for this error even if access() says it's OK,
because the permissions can change after you call access().

--

Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. Can't Alter My Path, Can't Find My Path

Here's the situation:

I'm a newbie logged in as root in KDE (I KNOW it's dangerous).  When I type
'echo $PATH' I get '/sbin:/usr/sbin:/usr/bin:/usr/X11R6/bin'.

In /etc/profile I found a path statement but it looks like it's part of a
sub-script and it doesn't match this path (it includes games).  I added a
'PATH=$PATH:/opt'  and an 'export PATH'.  I logged out and back in.  It made
no difference to my path statement.  I tried again with quote marks around
$PATH:/opt.  No difference.

I've checked the bash profile and bashrc.  I can't find where
'/sbin:/usr/sbin:/usr/bin:/usr/X11R6/bin' comes from.  I'm running Mandrake.

Where is the path hidden?  I've spent two days trying to find it on my own
following all the nice notes from LinuxNewbie.  I yield.  Help.

Thanks,
Ric

2. HELP: recovering data from an 8mm tape.

3. Commands to Find Common Base Path of 2 Given Paths?

4. Help need tunes

5. Execute scripts found by 'find' how?

6. cromemco appl.

7. copying / cloning a system disk, can't find an exact answer.

8. timer expires in ftape 2.08

9. Why does code fail to find *exact* amouut of RAM??

10. finding detailed descrip of exact Solaris boot up order

11. Newbie: Finding An Exact Substring Match In A File ???

12. Find exact creation time of a process; not kill a wrong process

13. exact syntix of find + touch ??