Download Solution: Click to Download Solution
Solution File Name: CSCCPE3350Lab3TheFalconShell.docx
Unzip Password: prestobear.com
1. (60 points) The Shell Program
Note: parameters in  are optional, parameters in <> are required. The | (pipe) means “or.”
• Invoking falsh, usage, and errors (5 points)
o Usage: falsh [ -h] The optional -h flag prints the help message (see below) and immediately exits.
o After invoking falsh, it runs until the user types the exit command.
o Errors should not end a falsh session. Instead, print an appropriate error message –
generally, this will be “command not found.”
• Handling whitespace (2 points)
o Note on whitespace: all commands typed into falsh should ignore leading and trailing
whitespace. For example, “ cd “ should work the same as “cd.” Tip: you
might want to start with an implementation that does not account for extra whitespace,
add it in last.
• Built-in Commands (18 points)
o Per the pseudocode above, falsh should handle built-in commands as special cases –
do not fork a child process, just handle these “directly” in the shell program.
o exit – exit the program
o pwd – print the current working directory. Tip: you should use the getcwd() function.
o cd – change directory.
Usage: cd [dir] If the optional dir is provided, change to the specified directory.
If no arguments are provided, change to the user’s home directory. Tip: use
getenv(“HOME”) to retrieve the user’s home directory.
Tip: you should use the chdir() function.
o setpath – sets the path, user must provide at least one argument (directory). The
path is where falsh will look for executable programs to run.
The path when falsh launches should contain only /bin.
User launches falsh
Path contains only /bin
User invokes: setpath /bin /usr/bin
Path now contains /bin and /usr/bin
User invokes: setpath /usr/share/bin
Path now contains only /usr/share/bin
o help – list all built-in commands with short, user-friendly descriptions.
o Redirection (15 points)
o Shells typically allow for redirection between programs. For example, in bash try the
following: echo blah > tmp_file_lab3.txt
In this example, nothing is printed to the screen and the text “blah” is instead directed
to the file tmp_file_lab3.txt. Note this file is truncated if it exists!
o You will implement simplified redirection in falsh: when the user invokes
command > filename, redirect command’s standard output to
argument or multiple arguments should not be allowed: print a useful error message
and do not run command.
o Other Commands (15 points)
o Any non-built-in command should be executed if it is in one of the directories specified
in the user’s path. Search the paths in the order entered by the user. Fork a child
process, pass appropriate arguments to exec, and wait for the child to return before
continuing to accept user input.