Extend your previous shell (homework 4) with I/O redirection (at least)
and some other nifty features.
assigned 4 Dec, due 10 Dec
The shell should print a prompt, allow the user to type any ordinary
Unix command, possibly with arguments, run that command until it
finishes, print another prompt, run another command, and so on until the
user types the special command "exit". You must handle I/O redirection:
if the user types a command followed by "> filename" or "< filename",
you should redefine stdout or stdin (respectively) to be the specified
file before running the command.
Some of you used the "system" function for homework 4, which is OK. But
I'd like to make sure you know how to use "fork", "exec", and "wait", and
how to pick apart a command line into words. So for homework 5,
please don't use the "system" function.
Picking apart a command line into words, recognizing punctuation marks
like ">" and "<", and recognizing special commands like "exit" and "cd"
is much easier with the help of lex, so I recommend writing all
or much of your shell as a lex program.
I/O redirection, pipes, semicolons, environment variable expansion (e.g.
"$TERM"), file completion, wildcard filenames, or the "~" directory
Other features to add
If you didn't get the variable shell-prompt, the "setenv" command, the
"cd" command, or the "exit" command to work properly in homework 4, fix
Other things to do for extra credit
Note: The last three of these require treating a
"command" as a unit within a line, rather than as
synonymous with a line. It may be easier to pick these things apart by
using yacc or bison in addition to lex or
- Environment variable expansion. If the command line typed by the
user includes a word preceded immediately by a dollar sign, e.g.
"$TERM", replace all this by the value of the environment variable; if
the variable has no value, print an error message rather than executing
- No-wait commands: if the command ends with "&", run the command
without waiting for it to finish.
- Multiple commands on a line: if the user types two or more commands
on a line separated by ";", execute each of the commands in order, waiting
for each one to finish before starting the next one.
- Multiple no-wait commands: if the user types two or more commands
on a line separated by "&", each one that ends with "&" should
be run without waiting for it to finish. For example, the command
"finger firstname.lastname@example.org & cc foo.c & ls"
would start three processes -- "finger", "cc", and "ls" --
and not wait for the first two to finish.
- Pipes: if the user types two commands separated by "|", run
the two simultaneously with the stdout of the first piped into the stdin
of the second.
Wed Dec 4 12:51:49 EST 1996
Stephen Bloch / email@example.com