Skip to content

Enhancing the user defined shell

Sarthak agarwal edited this page Oct 4, 2015 · 1 revision

**The goal of the project is to enhance the user defined interactive shell program that it can perform standard IPC operations, like pipes. It is able to handle file and stream buffers and should give proper perception of bourne shell. **

The following are the specifications for the project. For each of the requirement an appropriate example is given along with it.

####Specification 1: Implement input-output redirection functionality Output of running one(or more) commands must be redirected to a file. Similarly, a command might be prompted to read input data from a file and asked to write output to another file. Appropriate error handling must be done if the output file already exists or if an input file does not exist.

E.g. Output redirection
<Peytr@ICS231:~>diff file1.txt file2.txt > output.txt
E.g. Input redirection
<Peytr@ICS231:~>sort < lines.txt
E.g. Input-Output redirection
<Peytr@ICS231:~>sort < lines.txt > sorted-lines.txt

####Specification 2: Implement command redirection using pipes A pipe is identified by "|". One or more commands can be piped as the following examples show. Your program must be able to support any number of pipes.

E.g. Two Commands
<Peytr@ICS231:~>more file.txt | wc 
E.g. Three commands
<Peytr@ICS231:~>grep "new" temp.txt | cat - somefile.txt | wc

####Specification 3: Implement i/o redirection + pipes redirection

E.g.
<Peytr@ICS231 ~> ls | grep *.txt > out.txt
<Peytr@ICS231 ~> cat < in.txt | wc -l > lines.txt

#####General Notes *Useful commands : getenv, signal, pipe, dup2, wait, waitpid, getpid, kill, execvp, malloc, strtok, fork and so on.

  • Used fork() for creating child processes where needed and wait() for handling child processes
  • If the command cannot be run or returns an error it is handled appropriately. Looked at perror.h for appropriate routines to handle errors.
  • Did not used system() call anywhere.
  • The user can type the command anywhere in the command line i.e., by giving spaces, tabs etc.
  • The user can type in any command, including, ./a.out, which starts a new process out of the shell program. In all cases, the shell program is be able to execute the command or show the error message if the command cannot be executed.
Clone this wiki locally