To be able to execute a command, the shell needs to find where the command is located
first (in which folder or directory). For this, the shell uses an environment variable
called $PATH that defines search paths for a command. The path environment is a
list of directories, separated by colon ':'.
To see the contents of your $PATH variable in Unix, type at the shell prompt:
You should see something similar to this:
/bin:/usr/bin:/opt/gnu/bin:/usr/gnu/binThis information is used as follows. When you type in a command at the shell prompt, the shell looks for the executable file in the current directory first. If not found, the shell looks in the directories defined by the search paths in order: /bin first, then /usr/bin, and so on, until either the command is found or the search paths are exhausted. If the command is found, the shell executes it. If not found, the shell simply displays the message "Command not found".
Important Note: If the command name starts with the character '/' (root directory) or '.' (current directory), the search path is not used, because the path is explicitly mentioned.
quit, exit the program
path, print out a list of each of the values (or directories) of the current PATH environment variable, one per line.
One specific implementation requirement is to save the paths in an array of strings before printing them out. This will come in handy when we will build
more shell functionality in future assignments. Incorporate in your shell a function
that creates an array of strings, with each string being one path from the PATH environment variable.
For example, if the $PATH variable has the value shown above, then this function allocates memory for a global
variable searchpaths as shown below:
To implement the SaveSearchPaths function, use the functions InitArray and Insert from
the previous assignment. Then step 4 of this assignment reduces to
simply calling PrintAll.
Do not copy these functions into your smartshell1.c file. Just include the line
at the beginning of your smartshell1.c code, and compile it using the command
gcc smartshell1.c stringarray.c -o smartshell1The two source files will be linked into one executable file called smartshell1.
smartshelldirectory create a text file named
Readme, etc.) that contains:
Turn in a printout copy of the
readme file, and each of the three files (one printout per group). You will need to copy and paste your code into a text or a Word document in Windows, since you cannot print directly from Unix.
Leave the source code for all exercises in your directory csc1600/smartshell. Do not make any changes to these files after the due date for this assignment.
|50||Total points possible|
|10||Program compiles successfully and runs|
|15||Each command does something resembling the specified action|
|15||Each command works correctly and completely|
|5||You have added some extra "bells and whistles" (use your imagination)|
|5||Your readme file is present|