Let's show string comparison on some example grade file string age on first line start with shopping.
Ben Besh now we can create two string variables to first string variable sign.
Are you whole body
and to string to sign.
Hello body but with capital H.
Now we can compare both of them to see if they are equal or not into square brackets put dollar sign
single on equal sign dollar sign stating to.
And of course don't forget on double quotation marks next to variables.
So if that condition is true the print message equal if not visual print not equal
savefile
ground equal permission
and running
b c not equal which is scored because second string has capital H in the beginning.
I will go back to scrape and replace capital H with lowercase.
Now it should say equal so save the script.
Yeah and it does great.
Let's make some more changes.
Firstly Warbeck.
Keep it up.
Age instinct to
and for the if statement change singles for a bracket to double square brackets.
And in that case we don't need to use double quotation marks
now say the script and the right not equal grade.
It is working but to be sure what's changed back.
Capital H to lowercase
and now it should be in equal
and it does now it is up to VUDU really use for string comparison.
You can use single square brackets with quotation marks next to variables or just to use double square
brackets.
As I said previously mostly Are you single square brackets due to the fact that double brackets are
a kind of specific to beshe only and other shows don't use them.
Let's open the script again and I will show you how spaces can be dangerous.
But firstly change back from double square brackets to single one.
Now I remove the space next to the left bracket.
You can now safe descript and and we see the error message on line 6 but what's more descriptive Vasan
exited but it continued and a printed message not equal.
Even if our strings are completely equal here you see what simple space can do.
Because on every line vase at or it was a line number six.
It was for beshe false statement.
So the script continued to our statement that it is.
But in THINK OF NOT equal let's fix that space at our next door.
Well I've described a bracket
and do another one.
Now we can remove space next to equal sign.
When running we still got error message and printed message not equal.
So let's correct it.
And we see that now the message is equal.
Great.
Now I will clear the screen and we can do something more interesting.
Let's say that we want to create script which will print first.
So the lines of B s command but only in the case they use it or who are running it is rude.
The best way out to get no vote user is running descript Vody by using user ID we can print it using
equal dollar sign you I.D. here you see that my user ID is one thousand user id of root is zero.
You can check Basford file
and yes it does.
Similarly my user ID is confirmed to be 1000 but checking user ID would be a great example for mathematical
comparison and definitely you can try it on your own as a homework but as our lecture is about string
comparison we can use command where my what I will tell you what user you are.
So let's create a script called who don't as page
first line is usually dedicated to having been Bysshe on the next line.
I will print comment.
So we exactly know what we are going to show.
Three lines of B.S. come on only two road user
then our next line grade the variable.
Who am I.
And assigned to it using command substitution output of command.
Boy am I.
Now we can write if condition.
So inside single square brackets right dollar sign.
When I read double quotation marks of course then exclamation mark equal sign road road is also in double
quotation marks.
So if that condition is true that means if the user is not the root we can bring in.
You are not rude
exotic and of course we can exit with Stupples for example one
statement is not needed.
Just close the if statement.
And now we want to displace three lines of B s command.
So B S Desch eat f by hat Desch.
So the using command will print only first three lines of B as command.
Save descript ground execute permission.
And rallied.
You are not rude exiting.
Great.
It is working.
But to be sure I will switch to road user
by typing.
I will ensure that I am not home and now I can this could again
great.
I can see first the lines of B s command.
It is working perfectly.
I can now close the root session using exit keyboard and ensure that I am Richard.
Again.