Due Date: Thursday, October 18, 2005
Points: 100
One common assumption users of systems make is that they know which command is being executed when they tyoe the name of the command. This assignment asks you to create a tool to check this.
Your program is to be called "whereis". It should print the full path name of all instances of command in the search path.
Your program is to take 1 or more command-line arguments, each naming a command. It takes no other input.
Your program is to output the command followed by a colon and a blank-separated list of program names.
Here is an example run for one command (input and output). The "%" is a shell prompt:
% where viHere is an example run for two commands, the second having two versions:
vi: /usr/bin/vi
%
% where sh csh
sh: /bin/sh
csh: ./csh /bin/csh
%
The second command has two versions, one in the current working directory and the other in the /bin directory. If the user doesn't know about the first program, it could be a trap!
The search path is a list of directories separated by colons. If any entry is empty, (for example, "::"), the corresponding directory is the current working directory. For example, the search paths "/bin::/usr/bin" and "/bin:.:/usr/bin" are treated the same. When you type a command without a "/" in it, the shell looks in each directory in the list, and executes the first program with the same name as the command you typed.
The search path is stored in the environment variable PATH. To get it, use the library function getenv(3).