You are on page 1of 1

1 # Pappas Evangelos

2 # Operating Systems
3 # BHC 1st Semester Computing
4 # UNIX - Operating System
5 #____________________________________________________________________
6 #-------------------A Unix Script with Arguments.!------------------#
7 #-------------------------------------------------------------------#
8 if [ -n $1 -a $1 -eq "delete" -o $1 -eq "modify" ] #
9 then #-------Check the first argument that is given
10 query=`grep $2 ./passengers` #-------$2 is the Second Argument
11 if [ -n $query ] #
12 then #
13 touch passengers.tmp #-------A tmp File for Switching Files
14 sed s/$query/$3/ passengers > passengers.tmp #-------replace
15 cat passengers.tmp > passengers #
16 rm passengers.tmp #-------the tmp file is no longer necesary
17 else #-------when the 2nd query after delete/modify is null..!
18 echo "The stracture is:" #
19 echo "pscript [delete] [record to be replaced] [new record]" #
20 echo "pscript [new record]" #
21 fi #
22 elif [ -n $1 ] #-------If the query is not Empty
23 then #
24 query=`grep $1 ./passengers` #-------Look it up
25 if [ -z $query ] #------- if the query is not in the list
26 then #
27 lines=`wc -l passengers | cut -c 1-2` #-------10 lines Limitation
28 if [ $lines -eq 10 -o $lines -gt 10 ] #-------Check..!
29 then #
30 echo "WARNING! -> Only 10 lines are allowed to be written!!" #
31 else #
32 echo $1 >> passengers #-------Store it..!
33 fi #
34 else #-------and if the query is not empty, the record Exist..!
35 echo "The record Already Exists..!" #
36 echo . #
37 echo "The stracture is:" #
38 echo "pscript [delete] [record to be replaced] [new record]" #
39 echo "pscript [new record]" #
40 fi #
41 else #-------If there is no query at all..
42 echo "The stracture is:" #
43 echo "pscript [delete] [record to be replaced] [new record]" #
44 echo "pscript [new record]" #
45 fi #
46 touch passengers.tmp #
47 sort passengers > passengers.tmp #
48 mv passengers.tmp passengers #
49 rm passengers.tmp #
50 #-------------------------------------------------------------------#
51 #----------------------*~.:End Of the Script:.~*--------------------#
52 #___________________________________________________________________#

You might also like