1
00:00:02,580 --> 00:00:09,710
In this lecture we are going to create a script which can take some parameters so create a file called

2
00:00:09,710 --> 00:00:10,650
file check.

3
00:00:10,730 --> 00:00:16,070
As a start with siobhán on the first line

4
00:00:19,750 --> 00:00:23,610
and on the next line we can write what we are going to build.

5
00:00:23,800 --> 00:00:34,240
So write command write script which will work with parameters

6
00:00:37,670 --> 00:00:50,300
and it will be Desch F or dash file which will provide info about number of lines vorwärts and characters

7
00:00:50,360 --> 00:00:51,290
of some file

8
00:01:04,670 --> 00:01:10,000
of lines vorwärts and characters

9
00:01:13,100 --> 00:01:19,760
and we can also use Sparham meter dash age or dash dash help

10
00:01:25,620 --> 00:01:34,750
and these will provide each message so one time aura.

11
00:01:34,990 --> 00:01:43,680
The goal is to build our script with some barometers parameter or parameter file will take a value of

12
00:01:43,760 --> 00:01:49,990
a file pop and it will print a number of lines voids and characters in that file.

13
00:01:51,010 --> 00:01:56,120
Parameter age or a parameter or help will print usage of message.

14
00:01:56,180 --> 00:02:00,230
That means message how to use our script.

15
00:02:00,460 --> 00:02:07,810
So if you want to check what parameters were added We basically need to loop through all arguments so

16
00:02:07,840 --> 00:02:09,220
let's do it.

17
00:02:09,220 --> 00:02:11,000
We will use a while loop.

18
00:02:11,050 --> 00:02:18,020
So while a number of arguments are represented as a sign hash is greater than zero.

19
00:02:18,280 --> 00:02:23,720
Then perform commands between do and keyboards.

20
00:02:23,760 --> 00:02:30,840
Now we should check what is the first argument and for that reason we can use case statement.

21
00:02:31,100 --> 00:02:33,470
So case dollar sign or one

22
00:02:36,470 --> 00:02:38,270
in.

23
00:02:38,430 --> 00:02:47,460
So if the first argument is that age or degradation of legal pre-NDA usage message

24
00:02:57,150 --> 00:03:01,860
so this will override echo usage.

25
00:03:02,120 --> 00:03:12,620
Dollar Signs 0 which is the screen name and then the possibilities user has Desch H or does it help

26
00:03:14,090 --> 00:03:19,090
Desch efile or dash dash file followed by file pop

27
00:03:24,130 --> 00:03:27,920
and we can also exit discretely here as user.

28
00:03:27,930 --> 00:03:30,190
Don't know how to use the script that

29
00:03:34,500 --> 00:03:47,070
if the first arable land is Desch f or a dash dash file we should store a given file apart into variable

30
00:03:47,070 --> 00:03:53,760
file so I the lot of to into viable file

31
00:03:56,950 --> 00:04:05,160
but why we are using here go are assigned to because we are expecting to get filed back right after

32
00:04:05,160 --> 00:04:13,740
a user specified dish or Dish dish file but what happens if after dish or Dish dish file is not efile

33
00:04:13,850 --> 00:04:19,090
path we need to check if a file really exists.

34
00:04:19,660 --> 00:04:20,850
So we'll see.

35
00:04:20,890 --> 00:04:30,850
Using filed this update F and if that file doesn't exist we will print the file not exit's

36
00:04:34,860 --> 00:04:38,490
so eco file

37
00:04:41,300 --> 00:04:47,900
does not exits and will exit the script with exit status to

38
00:04:52,260 --> 00:04:59,130
now if we have existing file we need to find out how many lines of words and characters in the file

39
00:04:59,130 --> 00:04:59,820
has.

40
00:05:00,120 --> 00:05:10,030
So for all lines we will use command WC vate barometer our So lines for us.

41
00:05:10,250 --> 00:05:19,920
Cut the file and output of that cut command will give into standard input of command W see

42
00:05:23,420 --> 00:05:31,230
four of our ads will use command debri will see with meter W

43
00:05:42,740 --> 00:05:44,450
and for correctors

44
00:05:47,260 --> 00:05:51,150
it will be the same bandwidth parameter and

45
00:06:00,650 --> 00:06:08,100
but because we are assigning to a variable output of command we need to do command substitution.

46
00:06:08,300 --> 00:06:09,980
And I will do that.

47
00:06:09,980 --> 00:06:17,550
For example using batiks.

48
00:06:17,640 --> 00:06:25,470
Now we can print to user information about a number of lines of words and characters.

49
00:06:25,560 --> 00:06:29,070
So start with printing file name

50
00:06:33,220 --> 00:06:37,010
file Galarza on file.

51
00:06:38,980 --> 00:06:42,120
Then we can print number of lines

52
00:06:46,220 --> 00:06:53,240
so it got lines and this is two dollar sign lines.

53
00:06:53,240 --> 00:07:03,700
Then we can print number of boards so a number of words is represented by variable Lords.

54
00:07:05,270 --> 00:07:12,830
And then we can print number of characters which is represented by the characters

55
00:07:17,220 --> 00:07:17,780
we.

56
00:07:17,800 --> 00:07:21,550
And this case section using doubles and column

57
00:07:30,870 --> 00:07:35,620
and for a case that user will type something different.

58
00:07:35,700 --> 00:07:42,210
We are using asterisk which is a wildcard representation of any number of characters.

59
00:07:42,840 --> 00:07:53,680
And here we can be lazy and just use each line read Exit command and close the section using double

60
00:07:53,680 --> 00:07:56,180
semicolon.

61
00:07:56,330 --> 00:08:02,570
Now we can close the case statement all suck.

62
00:08:03,920 --> 00:08:08,880
But if you are looking carefully something is not right.

63
00:08:08,930 --> 00:08:14,090
We are at the beginning asking if number of arguments is greater than zero.

64
00:08:14,480 --> 00:08:18,230
But number of arguments is still the same and not changing.

65
00:08:18,440 --> 00:08:26,120
It would be nice to decrease the number of arguments after reports as arguments in case section and

66
00:08:26,120 --> 00:08:32,290
to our surprise we have such an option and it is using keyword shift.

67
00:08:32,830 --> 00:08:40,640
Every Varietes shift we are drawing ever a first argument so that means if we for example have five

68
00:08:40,640 --> 00:08:50,430
arguments and then brightened the first Tuvan is throw away and we have only four arguments so far.

69
00:08:50,450 --> 00:08:52,590
Desch F and dash dash.

70
00:08:52,670 --> 00:08:54,080
File S..

71
00:08:54,140 --> 00:08:58,640
We need to throw away that argument which represents parameter

72
00:09:03,530 --> 00:09:04,700
throw a

73
00:09:10,280 --> 00:09:15,290
parameters argument and also we need to throw away

74
00:09:18,070 --> 00:09:23,150
debt at a woman which is your presence file but

75
00:09:25,900 --> 00:09:27,690
that parameter is the value.

76
00:09:28,180 --> 00:09:36,130
So if user specified only Desch f followed by some file pop we now don't have any argument.

77
00:09:36,250 --> 00:09:46,770
And while we'll finish with this loop Eevee didn't have in the Help section exit commom We also would

78
00:09:46,770 --> 00:09:54,880
need to use command shift which will throw every argument which is represented by parameter Desch age

79
00:09:55,330 --> 00:09:58,990
or dash dash help.

80
00:09:59,240 --> 00:10:06,440
And in this section is not needed as help parameter is not followed by any value as it was in the file

81
00:10:06,480 --> 00:10:08,800
parameter.

82
00:10:08,830 --> 00:10:12,960
So one time more for the case user has specified.

83
00:10:13,090 --> 00:10:17,000
Or does this file followed by file path.

84
00:10:17,200 --> 00:10:24,920
We need to throw away two arguments as we don't want to come across those arguments again as Dave already

85
00:10:24,940 --> 00:10:32,750
puts us and forecast user specified Desch age or Degesch help we need to fro.

86
00:10:32,860 --> 00:10:40,240
Only one argument as is debt argument was already processed and we don't want to come across with it

87
00:10:40,420 --> 00:10:42,530
again.

88
00:10:42,580 --> 00:10:48,820
So now we can close the script ground execute permissions

89
00:10:53,050 --> 00:10:54,580
and run discrete

90
00:10:59,860 --> 00:11:04,950
but firstly let's see what we can read in the current directory.

91
00:11:04,960 --> 00:11:15,620
You'll see us so I will try to check that employee file from previous lecture and can see that I did

92
00:11:15,620 --> 00:11:18,740
it wrongly as I didn't specify file Paromita.

93
00:11:18,860 --> 00:11:22,540
So I have received the message.

94
00:11:22,610 --> 00:11:31,250
If I use parameter file with employee file I received the file stat..

95
00:11:31,350 --> 00:11:32,240
Great.

96
00:11:32,350 --> 00:11:38,160
I see 8 lines for divorce and 199 characters.

97
00:11:38,340 --> 00:11:39,290
Great.

98
00:11:40,000 --> 00:11:45,890
If I change file to some not existing I receive file doesn't exist.

99
00:11:45,940 --> 00:11:47,120
Great.

100
00:11:47,140 --> 00:11:56,230
Now I will try to change parameters Dish dish file to Desch F and I will also art Dish dish help.

101
00:11:59,760 --> 00:12:02,100
So I am using two buy meat that is either

102
00:12:04,970 --> 00:12:06,320
and great.

103
00:12:06,320 --> 00:12:08,280
I can see firer stat..

104
00:12:08,360 --> 00:12:14,060
And also I can see using message because I have also specified help barometer.

105
00:12:14,870 --> 00:12:22,010
So at the beginning of our script letter asking if number of arguments is greater than zero and it was

106
00:12:22,070 --> 00:12:30,600
we have three arguments then we went into K.S. and started to ask what is the first argument.

107
00:12:30,800 --> 00:12:33,030
First argument was Desch have.

108
00:12:33,140 --> 00:12:39,900
So we have prepared for our statistics for a second argument which has employee file.

109
00:12:40,120 --> 00:12:48,040
Then we have used shift 2 times which means that we get rid of Desch F and also we get rid of employee

110
00:12:48,040 --> 00:12:49,270
file.

111
00:12:49,300 --> 00:12:53,850
Now we have only one argument and it is Desch doesn't help.

112
00:12:54,280 --> 00:13:00,740
The script goes again from the beginning and asking Is number of arguments greater than zero.

113
00:13:01,030 --> 00:13:01,910
Yes it is.

114
00:13:01,930 --> 00:13:05,520
We have one argument that doesn't help.

115
00:13:05,560 --> 00:13:12,310
So we then go to the K section where we are asking for the first argument which is now help.

116
00:13:12,520 --> 00:13:19,330
And in that case we are printing usage message and exiting with Aristotle's one.

117
00:13:19,810 --> 00:13:26,320
If it didn't use exit command here we still have the shift to come on here which would throw away the

118
00:13:26,320 --> 00:13:27,490
first argument.

119
00:13:27,640 --> 00:13:29,670
In our case Desch didn't help.

120
00:13:29,800 --> 00:13:36,250
And then the script would continue to the beginning of viable where we are asking is the number of arguments

121
00:13:36,250 --> 00:13:37,960
greater than zero.

122
00:13:37,960 --> 00:13:38,970
No it isn't.

123
00:13:38,980 --> 00:13:40,980
We have zero arguments now.

124
00:13:41,080 --> 00:13:49,960
So the script would continue after dummy keyboard of vital.

125
00:13:49,980 --> 00:13:57,130
Now we can check some bigger file for example passport file and it works nice.

126
00:13:57,620 --> 00:14:03,680
So in this way you can create your own script with numerals but ammeters.
