This is an excerpt from the instructions of my homework for my operating systems class. The bolded portion is the part I cannot make sense of, nor can I reach the professor right now and I’d really like to start this tonight. I know what an environment variable is, I suppose…just a variable declared in the shell, right? But what does the bolded line in particular mean?
Write a C program to implement an interactive shell in which users execute commands.
Call this program myshell (so use gcc -o myshell -Wall etc. to
compile).Create an infinite loop that repeatedly prompts the user to enter a
command (see example output and input below).Before executing the command entered by the user, the command must be
found using the path specified by environment variable THEPATH (do not
use PATH!). By default, the THEPATH variable is not set, so for
testing, you’ll want to set (and unset) this variable manually (see
details below). If THEPATH is found, your program must execute the
command in a child process via fork() and one of the exec() system
calls.To obtain and parse THEPATH, consider using the getenv() function and
the strtok() or strsep() functions.
For a shell to run a program, it has to know where that program is. For example, you want to be able to type
lsat the prompt, but the actual binary forlsmight be found at/bin/ls. That’s wherePATH(or your case,THEPATH) comes in. When you typels, the shell goes off and looks in eachPATHdirectory for a program with a matching name. When it finds one, it runs it. Let’s uselsas an example, and aPATHset to:Assuming
lsis/bin/ls, then the shell first looks forlsin/usr/local/bin, doesn’t find it, then looks in/usr/bin, and then finally finds it in/binand executes it.Actually doing this operation is where the hint in your assignment about
getenv,strtok, andstrsepcomes in.