1
00:00:00,910 --> 00:00:12,240
Let's show string comparison on some example grade file string age on first line start with shopping.

2
00:00:12,520 --> 00:00:21,840
Ben Besh now we can create two string variables to first string variable sign.

3
00:00:21,940 --> 00:00:23,600
Are you whole body

4
00:00:26,730 --> 00:00:29,860
and to string to sign.

5
00:00:30,200 --> 00:00:33,810
Hello body but with capital H.

6
00:00:39,760 --> 00:00:48,410
Now we can compare both of them to see if they are equal or not into square brackets put dollar sign

7
00:00:48,490 --> 00:00:56,320
single on equal sign dollar sign stating to.

8
00:00:57,010 --> 00:01:06,130
And of course don't forget on double quotation marks next to variables.

9
00:01:06,300 --> 00:01:16,540
So if that condition is true the print message equal if not visual print not equal

10
00:01:22,920 --> 00:01:23,720
savefile

11
00:01:27,620 --> 00:01:29,270
ground equal permission

12
00:01:33,750 --> 00:01:34,310
and running

13
00:01:37,640 --> 00:01:44,920
b c not equal which is scored because second string has capital H in the beginning.

14
00:01:45,430 --> 00:01:59,710
I will go back to scrape and replace capital H with lowercase.

15
00:01:59,770 --> 00:02:04,160
Now it should say equal so save the script.

16
00:02:05,020 --> 00:02:07,380
Yeah and it does great.

17
00:02:07,870 --> 00:02:10,200
Let's make some more changes.

18
00:02:10,210 --> 00:02:11,920
Firstly Warbeck.

19
00:02:11,950 --> 00:02:12,460
Keep it up.

20
00:02:12,470 --> 00:02:14,980
Age instinct to

21
00:02:17,800 --> 00:02:25,150
and for the if statement change singles for a bracket to double square brackets.

22
00:02:29,310 --> 00:02:34,200
And in that case we don't need to use double quotation marks

23
00:02:38,580 --> 00:02:44,520
now say the script and the right not equal grade.

24
00:02:44,560 --> 00:02:47,980
It is working but to be sure what's changed back.

25
00:02:48,000 --> 00:02:50,020
Capital H to lowercase

26
00:02:53,200 --> 00:02:54,910
and now it should be in equal

27
00:02:58,300 --> 00:03:05,370
and it does now it is up to VUDU really use for string comparison.

28
00:03:05,580 --> 00:03:14,250
You can use single square brackets with quotation marks next to variables or just to use double square

29
00:03:14,280 --> 00:03:15,280
brackets.

30
00:03:15,570 --> 00:03:22,540
As I said previously mostly Are you single square brackets due to the fact that double brackets are

31
00:03:22,540 --> 00:03:28,370
a kind of specific to beshe only and other shows don't use them.

32
00:03:30,050 --> 00:03:35,570
Let's open the script again and I will show you how spaces can be dangerous.

33
00:03:35,900 --> 00:03:47,680
But firstly change back from double square brackets to single one.

34
00:03:47,690 --> 00:04:02,560
Now I remove the space next to the left bracket.

35
00:04:02,740 --> 00:04:15,840
You can now safe descript and and we see the error message on line 6 but what's more descriptive Vasan

36
00:04:15,950 --> 00:04:21,070
exited but it continued and a printed message not equal.

37
00:04:21,320 --> 00:04:28,150
Even if our strings are completely equal here you see what simple space can do.

38
00:04:29,960 --> 00:04:35,770
Because on every line vase at or it was a line number six.

39
00:04:36,040 --> 00:04:38,730
It was for beshe false statement.

40
00:04:38,980 --> 00:04:43,050
So the script continued to our statement that it is.

41
00:04:43,050 --> 00:04:50,630
But in THINK OF NOT equal let's fix that space at our next door.

42
00:04:50,720 --> 00:04:52,180
Well I've described a bracket

43
00:05:00,270 --> 00:05:02,680
and do another one.

44
00:05:03,330 --> 00:05:06,520
Now we can remove space next to equal sign.

45
00:05:08,660 --> 00:05:16,980
When running we still got error message and printed message not equal.

46
00:05:17,030 --> 00:05:18,640
So let's correct it.

47
00:05:31,140 --> 00:05:34,550
And we see that now the message is equal.

48
00:05:34,650 --> 00:05:36,010
Great.

49
00:05:36,030 --> 00:05:41,740
Now I will clear the screen and we can do something more interesting.

50
00:05:43,810 --> 00:05:48,790
Let's say that we want to create script which will print first.

51
00:05:48,820 --> 00:05:57,240
So the lines of B s command but only in the case they use it or who are running it is rude.

52
00:05:57,580 --> 00:06:07,810
The best way out to get no vote user is running descript Vody by using user ID we can print it using

53
00:06:08,260 --> 00:06:22,050
equal dollar sign you I.D. here you see that my user ID is one thousand user id of root is zero.

54
00:06:22,050 --> 00:06:23,850
You can check Basford file

55
00:06:31,740 --> 00:06:33,270
and yes it does.

56
00:06:33,540 --> 00:06:44,990
Similarly my user ID is confirmed to be 1000 but checking user ID would be a great example for mathematical

57
00:06:44,990 --> 00:06:54,680
comparison and definitely you can try it on your own as a homework but as our lecture is about string

58
00:06:54,740 --> 00:07:03,140
comparison we can use command where my what I will tell you what user you are.

59
00:07:03,140 --> 00:07:08,830
So let's create a script called who don't as page

60
00:07:11,840 --> 00:07:20,590
first line is usually dedicated to having been Bysshe on the next line.

61
00:07:20,610 --> 00:07:22,060
I will print comment.

62
00:07:22,140 --> 00:07:26,290
So we exactly know what we are going to show.

63
00:07:26,350 --> 00:07:35,730
Three lines of B.S. come on only two road user

64
00:07:40,050 --> 00:07:43,130
then our next line grade the variable.

65
00:07:43,140 --> 00:07:44,150
Who am I.

66
00:07:44,190 --> 00:07:49,360
And assigned to it using command substitution output of command.

67
00:07:49,370 --> 00:07:52,170
Boy am I.

68
00:07:52,290 --> 00:07:56,260
Now we can write if condition.

69
00:07:56,490 --> 00:08:00,680
So inside single square brackets right dollar sign.

70
00:08:00,900 --> 00:08:11,790
When I read double quotation marks of course then exclamation mark equal sign road road is also in double

71
00:08:11,790 --> 00:08:13,900
quotation marks.

72
00:08:14,490 --> 00:08:23,820
So if that condition is true that means if the user is not the root we can bring in.

73
00:08:23,960 --> 00:08:25,880
You are not rude

74
00:08:30,910 --> 00:08:37,720
exotic and of course we can exit with Stupples for example one

75
00:08:40,410 --> 00:08:42,200
statement is not needed.

76
00:08:42,450 --> 00:08:44,240
Just close the if statement.

77
00:08:45,640 --> 00:08:50,440
And now we want to displace three lines of B s command.

78
00:08:51,040 --> 00:08:56,810
So B S Desch eat f by hat Desch.

79
00:08:56,880 --> 00:09:05,490
So the using command will print only first three lines of B as command.

80
00:09:05,710 --> 00:09:10,470
Save descript ground execute permission.

81
00:09:15,550 --> 00:09:19,970
And rallied.

82
00:09:19,990 --> 00:09:22,040
You are not rude exiting.

83
00:09:22,300 --> 00:09:22,810
Great.

84
00:09:22,840 --> 00:09:23,760
It is working.

85
00:09:23,980 --> 00:09:27,820
But to be sure I will switch to road user

86
00:09:32,170 --> 00:09:33,360
by typing.

87
00:09:33,410 --> 00:09:40,180
I will ensure that I am not home and now I can this could again

88
00:09:44,540 --> 00:09:45,120
great.

89
00:09:45,170 --> 00:09:48,460
I can see first the lines of B s command.

90
00:09:49,670 --> 00:09:51,690
It is working perfectly.

91
00:09:51,920 --> 00:09:59,450
I can now close the root session using exit keyboard and ensure that I am Richard.

92
00:09:59,450 --> 00:09:59,890
Again.
