CSC 271
Homework 6
Assigned 17 Nov
Due 13 Dec
Enhance your shell (homework 5) with more
features. The more of them you do successfully, the more impressed I'll
be. I've listed some suggestions in roughly increasing order of
difficulty:
- If you didn't get homework 5 working, fix
it.
- A built-in "cd" command
- A built-in command to show the value of an environment variable
- A built-in command to change the value of an environment variable
- A built-in command to change the prompt your shell prints
- Running commands with "fork" and "exec" rather than "system".
- Allowing the user to specify more than one command on a line, using
semicolons to separate them (assuming you've already done #5 above; if
you're using
system
, the Bourne shell will take care of
this)
- Allowing the user to run commands without waiting for them to
finish, like the & feature in the standard shells (ditto)
- Handling pipes (ditto).
- Handling I/O redirection (ditto).
- Allowing the user to specify his/her own home directory easily, using
"~" as in csh
- Allowing the user to specify other users' home directories easily,
using "~username" as in csh
- Allowing the user to expand environment variables in the middle of a
command line, using "$variablename" as in csh (if you do this, you don't
really need #2 above)
- Making your shell run shell scripts nicely (i.e. taking
"#" to indicate a comment, not printing prompts during a script, etc.).
You can run a shell script either by typing
myshell
<script
or by
making the first line of the script "#!" followed by the complete
pathname of your shell, e.g.
#!/users/staff/math/sbloch/bin/myshell
.
- A simple history mechanism,
allowing the user to repeat the previous command, using "!!" as in csh.
- Allowing the user to repeat the most recent previous command that started
with a particular string, using "!string" as in csh.
- Allowing the user to replace part of a previous command with something
else, using "^old^new" as in csh.
- Expanding filename wildcards * and ? as in the standard shells
- Implementing "if...then...else". You may use one or both of the csh
syntaxes, or the sh syntax, or a reasonable syntax of your own; provide
documentation on how your version is to be used.
- Other neat features you think a shell should have...
Note: All of these can, in principle,
be done using just plain C or C++, but for several of them,
flex
will make your life enormously easier.
If you're doing more than one of #6-9, you may also need
yacc
or bison
to keep them all straight.
(Consider a command like
ls -l ; cat foo.c | wc
Does it run ls -l
and cat foo.c
, combining
their output and piping it to wc
, or does it run ls
-l
, then pipe the output of only cat foo.c
into
wc
? This is really an operator-precedence issue, just like
whether 3+4*5 evaluates to 23 or 35. flex
isn't good at
handling operator precedence, but yacc
and
bison
do it beautifully.)
Last modified:
Sun Oct 16 11:11:25 EDT 2005
Stephen Bloch / sbloch@adelphi.edu