D:\JavaFrameworks\InsuranceFramework\src\java\unix_code\ChangePremissionUnixScript.properties
  1 #!/bin/sh
  2 # *****************************************************************
  3 #
  4 #  This is an example of shell programming. It uses shell commands
  5 #  to illustrate the use of syntax of shell programming.
  6 #  It changes the premission on the file for user, group and others.
  7 #  It is an interactive program that uses LOOP, IF and CASE
  8 #  statement.
  9 #
 10 # *****************************************************************
 11 cls
 12 ls -al
 13 echo "\n\n\tThis program changes the file permission\n\n"
 14 echo "\n   enter (y/n) to proceede with the program\c"
 15 echo " =======> \c"
 16 read choice
 17 while [ $choice = 'y' -o $choice = 'Y' ]
 18   do
 19      cls
 20      ls -al
 21      echo "\n\t enter the file name  =====>  \c"
 22      read file_name
 23      echo "\n\t enter the name directory  - \c"
 24      echo "\tif current directory press (C or c)"
 25      echo "\n\t\t Directory name =====> \c"
 26      read dir_name
 27      if [ "$dir_name" != 'c'  -a "$dir_name" != 'C' ]
 28        then
 29          t_check=`/bin/ls $dir_name | grep $file_name`
 30        else
 31          t_check=`/bin/ls | grep $file_name`
 32        fi
 33      if [ "$t_check" !=  "$file_name" ]
 34       then
 35            echo "\n $file_name does not exist in $dir_name directory"
 36       else
 37            echo "\n $file_name is found"
 38            if [ "$dir_name" != 'c'  -a "$dir_name" != 'C' ]
 39              then
 40                  tfile_name="$dir_name/$file_name"
 41              else
 42                  tfile_name="$file_name"
 43              fi
 44            echo "\n\n\t$tfile_name   \tpress RETURN"
 45            read temp
 46            cls
 47            flag_1="off"
 48            flag_2="off"
 49            flag_3="off"
 50            echo "\n\nthe file name is $file_name\n\n"
 51            echo "`ls -al $tfile_name` \n"
 52            echo "To change  PERMISSION  on the  OWNER   (y/n) ==> \c"
 53            read entry
 54            if [ "$entry"  = 'y'  -o  "$entry"  = 'Y' ]
 55              then
 56                permission="u"
 57                flag_1="on"
 58              fi
 59            echo "To change  PERMISSION  on the  GROUP   (y/n) ==> \c"
 60            read entry
 61            if [ "$entry"  = 'y'  -o  "$entry"  = 'Y' ]
 62               then
 63                    permission="$permission""g"
 64                    flag_2="on"
 65               fi
 66            echo "To change  PERMISSION  on the  OTHER   (y/n) ==> \c"
 67            read entry
 68            if [ "$entry"  = 'y'  -o  "$entry"  = 'Y' ]
 69               then
 70                    permission="$permission""o"
 71                    flag_3="on"
 72               fi
 73            if [ "$flag_1" = "on"  -o  "$flag_2" = "on"   -o  "$flag_3" = "on" ]
 74               then
 75                   echo "\n\t 1) user read only         -1) user no read"
 76                   echo "\n\t 2) user write only        -2) user no write"
 77                   echo "\n\t 3) user execute only      -3) user no execute"
 78                   echo "\n enter the number or any other key to exit\c"
 79                   echo " ====> \c"
 80                   read choice_2
 81                else
 82                   choice_2="d"
 83                fi
 84            case "$choice_2"
 85                  in
 86                     1 )    chmod "$permission""+r"  $tfile_name;;
 87                    -1 )    chmod "$permission""-r"  $tfile_name;;
 88                     2 )    chmod "$permission""+w"  $tfile_name;;
 89                    -2 )    chmod "$permission""-w"  $tfile_name;;
 90                     3 )    chmod "$permission""+x"  $tfile_name;;
 91                    -3 )    chmod "$permission""-x"  $tfile_name;;
 92                     * )    echo "\n no choice is picked";;
 93                  esac
 94       fi
 95       echo "\n enter (y/n) to continue ===> \c"
 96       read choice
 97       if [ "$dir_name" != 'c'  -a "$dir_name" != 'C' ]
 98        then
 99           cd $dir_name
100        fi
101    done
102 echo "good bye -   press return to exit the prgram"
103 read chooice
104 
105