1
00:00:01,180 --> 00:00:06,730
Welcome to this lecture we are going to learn how to shorten the if statement.

2
00:00:06,940 --> 00:00:13,720
But firstly I will check what follows I have present here and if I am using Basho

3
00:00:16,200 --> 00:00:23,030
So if you want to write a statement we do it in following way.

4
00:00:23,640 --> 00:00:30,270
If then some condition then the statement for case of one condition is true.

5
00:00:31,050 --> 00:00:42,410
And then after our skeeball statement if condition is not true and we are ending with F

6
00:00:45,400 --> 00:00:48,940
and here we are testing if File hello.

7
00:00:49,090 --> 00:00:52,050
No text exists and it exists.

8
00:00:54,130 --> 00:00:58,960
I will change the file name to be sure that descriptive works great.

9
00:00:58,960 --> 00:01:01,370
It works fine.

10
00:01:01,430 --> 00:01:10,180
Now if you want to shorten if statement we are starting with square brackets then instead of give or

11
00:01:10,240 --> 00:01:17,960
and then we are using double ampersand and basically telling if that condition is true due to stuff

12
00:01:18,050 --> 00:01:22,940
after double ampersand and has it is working.

13
00:01:23,550 --> 00:01:28,390
If we use instead of double understandable pipe we are telling.

14
00:01:28,530 --> 00:01:34,230
If that condition is not true do the stuff after double type.

15
00:01:34,630 --> 00:01:39,670
So as a result we got no output as condition is true.

16
00:01:39,990 --> 00:01:43,190
If we change file name to some which doesn't exist

17
00:01:47,260 --> 00:01:51,870
we receive correct message doesn't exits.

18
00:01:52,250 --> 00:01:59,500
Let's make it more interesting and use in a one line double ampersand and double bind together.

19
00:01:59,530 --> 00:02:09,580
Many people think that the pipes here representing our statement but that's not true even it does look

20
00:02:09,850 --> 00:02:12,030
like the script is working correctly.

21
00:02:13,320 --> 00:02:18,760
And it is working correctly even for non existing file.

22
00:02:18,780 --> 00:02:21,250
We will see.

23
00:02:21,550 --> 00:02:31,540
So how it is working then we are starting with square brackets with condition that condition is returning

24
00:02:31,600 --> 00:02:33,060
exit status.

25
00:02:33,340 --> 00:02:37,070
Then we have a double ampersand followed by statement.

26
00:02:37,180 --> 00:02:41,680
That statement is executed only if exit status is zero.

27
00:02:43,060 --> 00:02:50,800
And then we have double pipe followed by statement and that statement is executed only if exit status

28
00:02:50,890 --> 00:03:01,420
is not zero but if statement after double ampersand is executed it is executed with some exit status

29
00:03:02,110 --> 00:03:06,700
which can be different from initial condition letter requested.

30
00:03:06,760 --> 00:03:17,430
If file exists so to realize what is going on would be best to change statement after that but ampersand

31
00:03:17,670 --> 00:03:21,790
into some command which will exit with non-zero status.

32
00:03:21,810 --> 00:03:30,590
For example being to not reachable IP address.

33
00:03:30,680 --> 00:03:33,620
And now if we executed this

34
00:03:42,380 --> 00:03:48,250
we see death being C'mon was clearly executed.

35
00:03:48,650 --> 00:03:58,400
But we also see message doesn't exist which is the best proven that there is no Alice statement at all.

36
00:03:58,400 --> 00:04:07,190
So once more file test condition and the route exit status of 0 and because of dead the pink Gaumont

37
00:04:07,280 --> 00:04:15,000
after double ampersand was executed being a command ended with exits that was the one.

38
00:04:15,290 --> 00:04:16,940
And because of death.

39
00:04:17,270 --> 00:04:25,980
But after double pipe was executed as that part is executed when exit status is not zero.

40
00:04:27,890 --> 00:04:34,190
We can use short if statement not only for final test operands we can't test anything.

41
00:04:34,220 --> 00:04:37,050
For example exits tattles.

42
00:04:37,190 --> 00:04:41,540
So if exit status is zero we can put in

43
00:04:44,410 --> 00:04:44,770
command.

44
00:04:44,770 --> 00:04:46,490
OK.

45
00:04:47,400 --> 00:04:52,880
And otherwise we will print something went wrong.

46
00:04:54,160 --> 00:04:58,770
That's basically Yukako month cannot be exited with non-zero exit status.

47
00:04:58,840 --> 00:05:03,580
We are using cadabra pipes here as our statement.

48
00:05:03,800 --> 00:05:13,840
And we can test if it is working on something which will exit with non-zeros those.

49
00:05:13,850 --> 00:05:18,110
So for example in our case bank being some reachable address

50
00:05:32,210 --> 00:05:35,220
and see that something went wrong.

51
00:05:35,270 --> 00:05:35,690
Great.

52
00:05:35,720 --> 00:05:37,390
It is working.

53
00:05:37,710 --> 00:05:41,800
Now it's time to create some small simple script

54
00:05:44,690 --> 00:05:51,560
so I'm creating file secret as I age and starting with siobhán.

55
00:05:52,490 --> 00:05:55,490
Then I ask guz for age

56
00:05:59,870 --> 00:06:05,520
and then really do variable called 8.

57
00:06:06,140 --> 00:06:14,810
Now we can ask if age is less than for example funding.

58
00:06:15,880 --> 00:06:17,650
And in that case we will print.

59
00:06:17,770 --> 00:06:24,100
You are not allowed to see the secret.

60
00:06:24,760 --> 00:06:32,350
You are not allowed to see the secret

61
00:06:35,270 --> 00:06:46,880
otherwise brain print Rock'em but it would be great to exit script when Duzer is displayed you are not

62
00:06:46,940 --> 00:06:48,070
allowed to see the secret.

63
00:06:48,110 --> 00:06:51,960
So we put Exit 1 after that message.

64
00:06:52,790 --> 00:06:54,960
And if you want to do multiple commands.

65
00:06:54,980 --> 00:07:03,260
After double ampersand or double pipe we need to put it into parenthesis or Carol-Lee brackets parentheses

66
00:07:03,410 --> 00:07:06,570
will create sub shell that those commands are.

67
00:07:06,980 --> 00:07:10,430
Which is not always good as you will see later.

68
00:07:11,900 --> 00:07:24,090
And at the end we will print that secret so we can print secret is that there is no secret save to file

69
00:07:31,520 --> 00:07:31,940
ground.

70
00:07:31,990 --> 00:07:33,090
Is it with permission

71
00:07:38,230 --> 00:07:38,920
and then.

72
00:07:40,560 --> 00:07:44,760
If you specify age 25 it works.

73
00:07:44,950 --> 00:07:54,820
Bhakt when I put age for example 15 something went wrong.

74
00:07:54,910 --> 00:07:56,820
I see all messages printed.

75
00:07:57,040 --> 00:07:58,760
So what has happened here.

76
00:07:59,880 --> 00:08:09,330
So I will open a script to show you that as I told you when we use parentheses comments are from in

77
00:08:09,330 --> 00:08:09,970
subcellar.

78
00:08:10,020 --> 00:08:18,060
Basically it means in another show an exit command only exited that shell and because thats actual written

79
00:08:18,340 --> 00:08:19,790
exit's that was the one.

80
00:08:19,800 --> 00:08:28,530
We also see the message of l.com because statements after double pipes are executed if exit status is

81
00:08:28,710 --> 00:08:29,890
not zero.

82
00:08:31,380 --> 00:08:38,670
So now let's change the script and instead of parentheses we will use Gardley brackets.

83
00:08:38,670 --> 00:08:49,500
Here it is important that after first first Gardley break it to have space and before that last curly

84
00:08:49,500 --> 00:08:51,710
break it to have a semicolon

85
00:08:55,790 --> 00:08:58,100
Now you can save descript

86
00:09:06,000 --> 00:09:06,650
and you can Adani

87
00:09:09,490 --> 00:09:11,630
for age 25.

88
00:09:12,510 --> 00:09:13,940
It works fine.

89
00:09:14,390 --> 00:09:23,430
And for age for example then also fine b c you are not allowed to see this secret great.
