06 March 2012

Do-It-Yourself (OpenGyan) - Write a (your own) shell

This is one of the exercises we give to students in our workshop on Linux programming. Many of the participants understand the concept behind the shell and use basic process management system calls (fork, exec, wait and exit) to write a miniature shell on their own. Given time (and effort), i think one can write their own shell. Here is the requirement for a brand new shell (feel free to assume/add more requirements). As an additional effort, try to find the features that are missing in existing shells and implement those in your new shell.
Write a mini-shell with a following features
  1. The shell should receive command from the user and execute it. If the user just gives the command, you have search the command in all of directories defined in the environment variable PATH. If you are not able to find the command, you have print "no luck, seems like your program is toasted". If the user specifies the path along with the program, it is enough if you just load and execute it.
  2. You should store the last command that is execute and its exit status.
  3. You should implement a facility to run the program in background.
  4. You should remember last “N” commands and print it upon user request.
  5. You should name your shell and it should appear as the prompt.
  6. When you type "quit", you must quit from your shell with a greeting.
Hope you find this interesting. Happy Shelling....