1
00:00:01,310 --> 00:00:09,360
OK so let's write some script where we can break this file system does operate this create a file called

2
00:00:09,840 --> 00:00:18,330
file test that age and that as you deal with siobhán bin bash.

3
00:00:18,360 --> 00:00:25,960
So what is wanted in this script for a provided file print summary

4
00:00:28,530 --> 00:00:32,270
of vote permissions user has granted

5
00:00:41,220 --> 00:00:47,620
but best be to do some examples to be sure that you fully understand what is wanted.

6
00:00:47,640 --> 00:00:53,560
So we roll around the script to read one argument some file name or a file path.

7
00:00:53,700 --> 00:00:55,890
And as a result we got.

8
00:00:56,220 --> 00:01:01,190
If that file is for us readable right to go our executor will

9
00:01:05,390 --> 00:01:28,940
so we receive some eco C'mon some message which is which says if the file is readable ridable or actable.

10
00:01:29,140 --> 00:01:32,960
Now we can start with.

11
00:01:33,020 --> 00:01:41,870
I will check because we want only one and one 5.

12
00:01:42,480 --> 00:01:49,110
So if number of our demands is not equal to 1

13
00:01:51,870 --> 00:01:52,840
we can bring in

14
00:01:56,970 --> 00:02:13,330
provide exactly one I will land and you can also exit here with startles one.

15
00:02:13,340 --> 00:02:16,560
Now you can also assign a variable.

16
00:02:17,000 --> 00:02:22,920
So in variable called File we are assigning a value of argument one.

17
00:02:22,970 --> 00:02:33,480
First I will add some command or so here variable assignment.

18
00:02:34,310 --> 00:02:44,830
Now we can check if dead file the first and only one argument is an existing file.

19
00:02:44,870 --> 00:02:47,170
So right in square brackets

20
00:02:50,250 --> 00:02:57,160
an operator and then file file variable.

21
00:02:57,240 --> 00:03:00,110
If that file exists we should do right.

22
00:03:00,210 --> 00:03:09,380
If you can read override or exec a file for death I will create new variables which will keep value

23
00:03:09,410 --> 00:03:10,320
yes or no.

24
00:03:17,340 --> 00:03:20,230
So some command here.

25
00:03:20,620 --> 00:03:26,090
Default variables and I will start the read variable.

26
00:03:26,340 --> 00:03:27,510
So Vita read

27
00:03:31,090 --> 00:03:33,310
equals two values.

28
00:03:33,370 --> 00:03:35,240
No.

29
00:03:35,530 --> 00:03:38,150
Right right equals two value.

30
00:03:38,780 --> 00:03:40,300
No.

31
00:03:41,080 --> 00:03:46,830
And exec equals to.

32
00:03:47,010 --> 00:03:47,830
No.

33
00:03:48,520 --> 00:03:50,390
All of them will have a value.

34
00:03:50,410 --> 00:03:51,400
No.

35
00:03:52,040 --> 00:03:54,040
And that is not true.

36
00:03:54,050 --> 00:03:56,960
We will change it later.

37
00:03:56,980 --> 00:04:01,260
Now we can check if file is readable.

38
00:04:02,230 --> 00:04:10,120
So if break bracket and use our operator for checking if the file is readable

39
00:04:12,980 --> 00:04:21,480
if a file is readable we can change the value of a variable to read to S..

40
00:04:21,710 --> 00:04:28,190
That means that the file is readable.

41
00:04:28,590 --> 00:04:37,740
Now we will check if file is right to go and for that we will use w operator.

42
00:04:38,040 --> 00:04:49,490
So check if he's right to go if and in square bracket we are using W operator

43
00:04:57,400 --> 00:05:03,060
and if that file is a right to go we need to change the value of variable.

44
00:05:05,190 --> 00:05:06,390
Write to us

45
00:05:12,480 --> 00:05:17,950
and check is if that file is executable.

46
00:05:19,900 --> 00:05:28,170
So check if file is.

47
00:05:28,500 --> 00:05:40,320
So for doing this check we will use operator X and of course if you need to assign value yes to variable

48
00:05:40,710 --> 00:05:50,730
via exec.

49
00:05:51,160 --> 00:05:53,960
Now we have or they don't need it.

50
00:05:54,160 --> 00:06:02,780
So we can print to user some summary some summary so you can Bryde eco

51
00:06:06,880 --> 00:06:13,660
but maybe Firstly I write some command here write somebody to user

52
00:06:20,360 --> 00:06:23,310
and on the first go here we will write

53
00:06:26,470 --> 00:06:27,360
read.

54
00:06:28,110 --> 00:06:32,830
And here we are putting the value of a variable.

55
00:06:32,870 --> 00:06:33,950
What I did.

56
00:06:34,320 --> 00:06:46,320
So it may be yes or no on the next line we will print value of variable.

57
00:06:46,340 --> 00:06:48,260
Var right.

58
00:06:49,230 --> 00:06:53,800
And on the next line we will print a value of variable var.

59
00:06:54,150 --> 00:07:00,230
So X exec to double Vajra and

60
00:07:05,820 --> 00:07:10,120
and maybe we can do also some fancy either for that

61
00:07:13,710 --> 00:07:18,090
so we can use another e-com

62
00:07:25,420 --> 00:07:32,070
file and we can based out both of the file variable

63
00:07:36,250 --> 00:07:37,670
but that's not all.

64
00:07:37,680 --> 00:07:42,370
We finished only the part for the case that file exist.

65
00:07:42,840 --> 00:07:44,650
If file doesn't exist.

66
00:07:44,650 --> 00:07:50,640
We can print something as vote file variable does not exist.

67
00:07:53,100 --> 00:08:01,100
So right you go to sign the file does not exist.

68
00:08:02,810 --> 00:08:04,980
Now we are done.

69
00:08:05,120 --> 00:08:07,560
So you can save descript

70
00:08:12,580 --> 00:08:14,200
ground with permission

71
00:08:18,650 --> 00:08:26,110
and we can meet but firstly create some test file using Dutch.

72
00:08:26,300 --> 00:08:27,220
Dutch Hello.

73
00:08:27,350 --> 00:08:35,380
Dot text and also create some testing directories so M-K dear

74
00:08:37,960 --> 00:08:41,660
directory.

75
00:08:41,740 --> 00:08:47,820
Now we see that we have one script one file and one directory.

76
00:08:48,270 --> 00:08:56,100
So now around the script firstly without an audible one works fine.

77
00:08:56,100 --> 00:09:04,700
Now we can use Hello text as an argument and we can see that we have read and write permissions.

78
00:09:04,740 --> 00:09:05,590
Great.

79
00:09:05,850 --> 00:09:14,940
So now we just grand exit could permission to that file Hello dot text and run the script again.

80
00:09:15,660 --> 00:09:16,290
Great.

81
00:09:16,290 --> 00:09:16,890
It works.

82
00:09:16,890 --> 00:09:20,080
We can see that we have also exit permissions.

83
00:09:20,160 --> 00:09:28,430
Now we can try to provide file with Hobart for example been beshe great.

84
00:09:28,440 --> 00:09:29,790
It also works.

85
00:09:30,150 --> 00:09:34,840
But what would happen if we specify our directory

86
00:09:37,810 --> 00:09:43,740
we see message that dedicatory doesn't exist which is correct such a file really doesn't exist.

87
00:09:44,000 --> 00:09:49,010
Same would be definitely for directory for example been

88
00:09:53,050 --> 00:09:59,680
so ran script again vate directory called Ben

89
00:10:04,730 --> 00:10:06,790
Oh no not been very sorry.

90
00:10:07,160 --> 00:10:14,880
It's been only been you see that been doesn't exist but I don't like that behavior.

91
00:10:14,900 --> 00:10:22,210
It would be much better to print to or that the argument provided is a directory Dubin is a directory.

92
00:10:22,260 --> 00:10:35,820
So open our script again and we can change their behavior for a case when file does not exist.

93
00:10:36,710 --> 00:10:39,480
But it is directory instead.

94
00:10:40,490 --> 00:10:41,680
So open file

95
00:10:49,270 --> 00:10:51,450
and under our state command

96
00:10:55,500 --> 00:11:03,150
we'll do some new if statement and we'll ask if we do

97
00:11:06,120 --> 00:11:20,010
file if the of file variable is not a directory and if it is a dedicatory we will print that value of

98
00:11:20,070 --> 00:11:23,490
an argument is a directory.

99
00:11:23,970 --> 00:11:29,250
Otherwise we will write that file does not exist.

100
00:11:34,890 --> 00:11:42,320
So we can also prebend before the value of variable file file.

101
00:11:42,400 --> 00:11:47,220
So file and devolve or variable file does not exits.

102
00:11:47,340 --> 00:11:54,790
And now we can save the script and we can try to run it again at agreement.

103
00:11:54,960 --> 00:12:01,010
It's like a big and we see now that slash and burn is directory.

104
00:12:01,350 --> 00:12:01,910
Great.

105
00:12:03,870 --> 00:12:06,270
So now we have break this file.

106
00:12:06,270 --> 00:12:10,450
Test operators and I can mention that they are usually used.

107
00:12:10,530 --> 00:12:17,310
And it is good to know them especially they are used for some backup scripts where we can for example

108
00:12:17,310 --> 00:12:25,660
check if destination for that exists and if not we can create it as backup is sometimes done to timestep

109
00:12:25,670 --> 00:12:26,710
folders.

110
00:12:26,970 --> 00:12:34,440
You can imagine a situation in a company which does daily backup and for current day it is already some

111
00:12:34,440 --> 00:12:35,520
backup done.

112
00:12:35,850 --> 00:12:42,990
So it can be time consuming to do because again if it is already done by checking if times then for

113
00:12:42,990 --> 00:12:52,000
the exits and it has some file in it's v. Vaughn do any more useless copying of files.

114
00:12:52,040 --> 00:12:55,650
So thanks for watching and see your next lecture.
