CSC 271
Homework 5

Assigned 17 Nov
Due 13 Dec

Enhance your shell (homework 4) 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:

  1. If you didn't get homework 4 working, fix it.
  2. A built-in "cd" command
  3. A built-in command to show the value of an environment variable
  4. A built-in command to change the value of an environment variable
  5. A built-in command to change the prompt your shell prints
  6. Running commands with "fork" and "exec" rather than "system".
  7. Allowing the user to specify more than one command on a line, using semicolons to separate them (assuming you've already done #6 above; if you're using system, the Bourne shell will take care of this)
  8. Allowing the user to run commands without waiting for them to finish, like the & feature in the standard shells (ditto)
  9. Handling pipes (ditto).
  10. Handling I/O redirection (ditto).
  11. Allowing the user to specify his/her own home directory easily, using "~" as in csh
  12. Allowing the user to specify other users' home directories easily, using "~username" as in csh
  13. 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 #3 above)
  14. 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.
  15. A simple history mechanism, allowing the user to repeat the previous command, using "!!" as in csh.
  16. Allowing the user to repeat the most recent previous command that started with a particular string, using "!string" as in csh.
  17. Allowing the user to replace part of a previous command with something else, using "^old^new" as in csh.
  18. Expanding filename wildcards * and ? as in the standard shells
  19. 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.
  20. 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 #7-10, 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: Fri Oct 12 10:18:17 EDT 2007
Stephen Bloch / sbloch@adelphi.edu