views:

75

answers:

4

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 anyone know where "wc" is hiding?

+6  A: 

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.

Thomas
+1  A: 

I tried whereis wc and I get it in /usr/bin/wc

No one in particular
Thanks. I got the same result just now.
learning
A: 

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.

Zack
A: 

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 /binor /usr/bin, or in places like /usr/local/bin or /usr/site/bin.

Loadmaster