EEL 602 - Operating Systems
Spring 2007
Indian Institute of Technology Delhi, New Delhi



Assignment 1

UNIX Shell Programming - Scripting with BASH

The objective of this assignment is to examine your familiarity in Unix shell scripting using the bash shell.

Create a script called srchengn that will print the lines matching a pattern from a set of files/folders. Your script should support the following options.  

 Syntax :

          srchengn    options     pattern     [FILE...]

 Options :   

        -f                   Searches the contents of the file/s specified by [FILE...] and displays the line containing the pattern        

                            on the standard output and display error message when the file was not found.


       -F                   Search for the string in all the files present in the given directory.


      -d                    Searches all the files present in the directory/s for the string specified and the result is displayed on the

                            standard output and display error message when the directory was not found

      -n                    Output along with line numbers in which the string is found


      -o                     Output to a file specified. This option will be used along with  other options like -f/-F/-D etc.


      -r/-R                 Search all files under each directory, recursively;


      -i                      Ignore case distinctions in both the PATTERN and the input files.


      -m                     Finds the frequency of the given string in the given file/directory.
 

      -h / -?                 Output a brief help message.

when no options are given then it has to show the syntax for the input.

 

Example Run :


[eel602@COSMOS shell]$ ./srchengn.sh -f echo 1.sh
echo "Enter the name and number of the student"
echo " student name is $nm and the entry number is $no "
echo "$i $j"
echo "$k "
echo "hi $user the number of users logged in are $numusers"

[eel602@COSMOS shell]$ ./srchengn.sh -f echo 1.sh 2.sh
1.sh:echo "Enter the name and number of the student"
1.sh:echo " student name is $nm and the entry number is $no "
1.sh:echo "$i $j"
1.sh:echo "$k "
1.sh:echo "hi $user the number of users logged in are $numusers"
2.sh: echo " Hi $user u got the required info "
2.sh:echo " This is ouput from the second file "

[eel602@COSMOS shell]$ ./srchengn.sh -f echo 1.sh 2.sh -o output
[eel602@COSMOS shell]$ vi output
1.sh:echo "Enter the name and number of the student"
1.sh:echo " student name is $nm and the entry number is $no "
1.sh:echo "$i $j"
1.sh:echo "$k "
1.sh:echo "hi $user the number of users logged in are $numusers"
2.sh: echo " Hi $user u got the required info "
2.sh:echo " This is ouput from the second file "
~
~
~
~
~

Assumptions

    1. Options may be combined (e.g. srchengn -d -i -m  pattern  /root/home/eet052901 -o output).

    2. The script must display proper error messages in the event of error (e.g. srchengn -d oper 1.sh (print an error message illustrating that the destination is not a folder).

    3. Don't use any standard pattern matching utilities provides by UNIX shell.

    4. Multiple files and Multiple folders can be specified at the command prompt.

 

Suggestions

 

      1. Use proper naming conventions.

     2. Use the concept of functions for modularity.

     3. Code must properly commented.


Points Distribution  [Maximum 20]

1. Implementing help (-h / -?)  ->  5%

2. For output to file (-o)  ->  5%

3. Implementing -f -> 5%

4. Implementing -i -> 5%

5. Implementing no option -> 5%

6. Implementing -F -> 8%

7. Implementing -m -> 8%

8. Implementation of the option -n -> 8%

9. Implementation of the option -d -> 15%

10.Implementation of the option -r -> 16%

11. Implementation of support for multiple command line options -> 20%

12. Clarity, Formatting and General Layout -> Up to xx if not followed

13. Originality -> Both copier and originator gets ZERO

14. Late Policy ->  20% reduction, allows ONLY one day delay.

Submission

Please submit a tar file on-line containing the following:

The name of the tar file must be Entryno_assign1 (Ex 2005EET2901_assign1) and can be uploaded in the assignment # 1 using this link. Please make sure that you upload the assignment only once. In case of multiple submission ONLY first submission will be used for grading.

Deadline

The submission deadline for the assignment # 1 is 20 January 2007 [23:59 Hrs].

Questions

If you have any further questions relating to this assignment, you may contact the TA, Mr. VENU KESAM [2005EET2901].