CSc 352: Assignment-7: Shell Scripts

Due Monday, August 5- 3pm

The assignment name for turnin is cs352_hw7

  1. Script 1: matrix.csh  Create a script named matrix.csh that will take as input two command line arguments.  These arguments represent the number of rows and columns in a matrix.  The script is to print out a matrix in which the first entry of the ith row is i.  The second entry of row i is i + 1, and so on.  So the entry of row i and column j should be i + j - 1.  Moreover, no entry is to have more than a single digit, so the script should output only the least significant digit of i + j - 1 (the % operator will be handy for this).   Below are a few examples of the expected output.  Your script should verify that at least two command line arguments have been given by the user.  You can ignore more than two, but if there are fewer than two, emit a usage message and exit.  The usage message should be  "Usage: matrix.csh rows columns"  (make it so that if you rename the script, the message will still be correct. For example if you name the script egk.csh, the message will be Usage: egk.csh rows columns).  You do not need to check that the arguments are actually numbers. (Suggestion: nested while loops)

    lec> matrix.csh 3 8
    1 2 3 4 5 6 7 8
    2 3 4 5 6 7 8 9
    3 4 5 6 7 8 9 0
    lec> matrix.csh 4 3
    1 2 3
    2 3 4
    3 4 5
    4 5 6
    lec>
    lec> matrix.csh 2 25
    1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
    2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
    lec> matrix.csh 3
    Usage: matrix.csh rows columns
    lec>


  2. Script 2: calc.csh  Create a script that will take as input three command line arguments, the first an integer, the second an operator, and the third another integer. Your script is to perform the operation on the two integers and output the result. Valid operators are plus, minus, times, div, and mod. Any other operator is invalid and will result in an error. You are to use a switch to discover which operator is given. Below are example inputs and corresponding outputs. Name your script calc.csh

    lec> calc.csh 100 minus 10
    100 minus 10 = 90
    lec> calc.csh 100 times 10
    100 times 10 = 1000
    lec> ./calc.csh 30 div -3
    30 div -3 = -10
    lec> calc.csh 17 mod 5
    17 mod 5 = 2
    lec> calc.csh 17 5
    Usage: calc.csh integer1 operator integer2
    lec> calc.csh 17 milk 5
    calc.csh: Operator milk not recognized.



  3. Script 3: findtypes.csh  Create a script named findtypes that takes two arguments, the first a directory name, the second a character from {r, x, o, f, w, e, z, d}. The script is to search the directory specified and recursively search all of its subdirectories. The second argument represents a csh/tcsh file query flag. The script is to search for all files that satisfy the given query flag. For example
    findtypes . f

    will report the names of all ordinary files in the current directory and all subdirectories of the current directory, and

    findtypes ~ e

    will report all files that exist in the users home directory and subdirectories. Below is a list of query types and their meaning.
     type report a file if it:      type report a file if it:
    ris readable by the user     wis writable by the user
    xis executable by the user     eexists
    ois owned by the user     zis of size zero
    fis an ordinary file     dis a directory