Population

Script Language Assignment

    A.First Edition

    This is totally CRAP, GARBAGE, TRASH or whatever you want to call it!!!!!!!

    B.The problem

C.The idea of program

    I stole the code from my classmate and make some copy jobs.

    1. I corrected the bug of subscription bug when user input "cd" with no param.

    2. I add the functionality to filter "." and ".." when option "-all" is input.

    3. I add sorting options for "-biggerthan" and "smallerthan".

    4. Corrected several small bugs like wrong "endif", "endbw".

    D.The major functions

    C.Further improvement

    It is a shameful thing to post it, however I have to do it, just record what I have done.

    กก

    #!/bin/tcsh

    while( ! $?x )

      echo -n "mydv:"

    set argmydv= ($<)

       if ( $#argmydv ) then

         switch ( $argmydv[1] )

         case 'cd':
    	 if ( $#argmydv >= 2 ) then
              if ( -d $argmydv[2] ) then

              cd $argmydv[2]

              else

              echo -n "The directory $argmydv[2] does not exist "

              endif
    	endif

         breaksw

         case 'dl':

              if ( $#argmydv == 2 ) then
    			  ls -lA |awk '{if ( $9 == "." || $9 == ".." ) next; print ;}'
              endif

              if ( $#argmydv == 3 ) then

                      switch ( $argmydv[2] )

                      case '-range' :
                      ls -l|awk '$9 ~ /^['$argmydv[3]']/'
                      breaksw

                      case '-modified' :
                      ls -l|awk '$6 == "'$argmydv[3]'"'
                      breaksw

                      case '-biggerthan' :
                      ls -l|awk '$5 > '$argmydv[3]''|sort -k 5
                      breaksw

                      case '-smallerthan' :
                      ls -l|awk '$5 < '$argmydv[3]''|sort -rk 5
                      breaksw

                      endsw

               endif

               if ( $#argmydv == 4 ) then

                      switch ( $argmydv[2] )

                      case '-all' :
                                     switch ( $argmydv[3] )
                                     case '-range' :
                                     ls -lA|awk '{if ( $9 == "." || $9 == ".." ) next; print ;}'|awk '$9 ~/^['$argmydv[4]']/'
                                     breaksw
                                     case '-modified' :
    					ls -lA|awk '{if ( $9 == "." || $9 == ".." ) next; print ;}'|awk '$6 == "'$argmydv[4]'"'
                                     breaksw
                                     case '-biggerthan' :
    					ls -lA|awk '{if ( $9 == "." || $9 == ".." ) next; print ;}'|awk '$5 > '$argmydv[4]''|sort -k 5
                                     breaksw
                                     case '-smallerthan' :
    					ls -lA|awk '{if ( $9 == "." || $9 == ".." ) next; print ;}'|awk '$5 < '$argmydv[4]''|sort -rk 5
                                     breaksw
                                     endsw

                       breaksw
                       case '-modified' :
    				ls -l|awk '{if ( $9 == "." || $9 == ".." ) next; print ;}'|awk '$6 == "'$argmydv[3]'" && $7 == '$argmydv[4]''
                       breaksw
                       endsw

             endif

             if ( $#argmydv == 5 ) then
                    ls -lA|awk '$6 == "'$argmydv[4]'" && $7 == '$argmydv[5]' '
             endif

         breaksw

         default:

         $argmydv

         endsw

       endif

    end