UNIX: Physical Location of "wc" command. It ain't "/bin"
This has be stump. I wrote a shell program in C that allows the user to execute several commands. Based on my research so far, all the commands such as "ls" and "cat" are located in "/bin/".
The "wc" is not listed in this directory - "/bin". If I fire up a terminal, I can type "wc fileName" and it works. I ran "find . wc" from the "/" directory, and I still can't find the "wc" command.
Does anyo开发者_JAVA技巧ne know where "wc" is hiding?
Try typing which wc
into your shell...that should tell you where it is.
On my machine it is in /bin/
.
However, if you just want the path resolution to be done on it's own, you can use the system()
function (see man 3 system
for more information). As you can read in the documentation, that's really the same as invoking the Bourne shell (or wherever the symlink for that points to) for the path resolution, so if you don't want that overhead, you will want to stick with whatever method you are currently using.
I tried whereis wc
and I get it in /usr/bin/wc
If you don't want to worry about where individual utilities are, but you do want to avoid the overhead involved in calling system
, then you should try the middle-level function execvp
, or one of its friends (also listed on that page). Sadly, there is no execvpe
.
You can try whence
, which
, or whereis
to find any program in your exec path, depending on which shell you're using.
Utilities like wc
are usually located in /bin
or /usr/bin
, or in places like /usr/local/bin
or /usr/site/bin
.
精彩评论