The project must be programmed in C, and may be created and run on the department Unix or Linux system, or in an install of Unix or Linux on your own machine.
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".
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. (Note that you may not use the command
echo $PATHto accomplish this.)
Use the function getenv to obtain a pointer to the string representing the $PATH variable. Copy this string into a local buffer, then use the function strtok to extract individual tokens from the string. The delimiter in this case is the colon character.
history-- display a numbered list of all previous commands
run #-- run the command numbered # from the history list
One efficient way of doing this is to save each user command into an array of strings,
and save this array in a file, say
history.txt, just before your smartshell ends.
(You will need to use
When you next invoke your smartshell executable, have it read the history of commands from
history.txt before beginning to process user commands, so that
so the history of commands is available to the current shell instance. The current shell
instance may add more commands to the history (and save it before finishing execution).
This way the history of shell commands is preserved between different shell executions.
Leave the source code in your directory csc8400/smartshell. If you work on your own computer, demonstrate your program and email the source code to your instructor.
|100||Total points possible|
|30||Program compiles successfully and runs|
|30||Each command does something resembling the specified action|
|30||Each command works correctly and completely|
|10||You have added some extra "bells and whistles" (for example, add a "mem" command that prints out the amount of memory available -- use your imagination)|