Welcome to this lecture we are going to learn how to shorten the if statement.
But firstly I will check what follows I have present here and if I am using Basho
So if you want to write a statement we do it in following way.
If then some condition then the statement for case of one condition is true.
And then after our skeeball statement if condition is not true and we are ending with F
and here we are testing if File hello.
No text exists and it exists.
I will change the file name to be sure that descriptive works great.
It works fine.
Now if you want to shorten if statement we are starting with square brackets then instead of give or
and then we are using double ampersand and basically telling if that condition is true due to stuff
after double ampersand and has it is working.
If we use instead of double understandable pipe we are telling.
If that condition is not true do the stuff after double type.
So as a result we got no output as condition is true.
If we change file name to some which doesn't exist
we receive correct message doesn't exits.
Let's make it more interesting and use in a one line double ampersand and double bind together.
Many people think that the pipes here representing our statement but that's not true even it does look
like the script is working correctly.
And it is working correctly even for non existing file.
We will see.
So how it is working then we are starting with square brackets with condition that condition is returning
exit status.
Then we have a double ampersand followed by statement.
That statement is executed only if exit status is zero.
And then we have double pipe followed by statement and that statement is executed only if exit status
is not zero but if statement after double ampersand is executed it is executed with some exit status
which can be different from initial condition letter requested.
If file exists so to realize what is going on would be best to change statement after that but ampersand
into some command which will exit with non-zero status.
For example being to not reachable IP address.
And now if we executed this
we see death being C'mon was clearly executed.
But we also see message doesn't exist which is the best proven that there is no Alice statement at all.
So once more file test condition and the route exit status of 0 and because of dead the pink Gaumont
after double ampersand was executed being a command ended with exits that was the one.
And because of death.
But after double pipe was executed as that part is executed when exit status is not zero.
We can use short if statement not only for final test operands we can't test anything.
For example exits tattles.
So if exit status is zero we can put in
command.
OK.
And otherwise we will print something went wrong.
That's basically Yukako month cannot be exited with non-zero exit status.
We are using cadabra pipes here as our statement.
And we can test if it is working on something which will exit with non-zeros those.
So for example in our case bank being some reachable address
and see that something went wrong.
Great.
It is working.
Now it's time to create some small simple script
so I'm creating file secret as I age and starting with siobhán.
Then I ask guz for age
and then really do variable called 8.
Now we can ask if age is less than for example funding.
And in that case we will print.
You are not allowed to see the secret.
You are not allowed to see the secret
otherwise brain print Rock'em but it would be great to exit script when Duzer is displayed you are not
allowed to see the secret.
So we put Exit 1 after that message.
And if you want to do multiple commands.
After double ampersand or double pipe we need to put it into parenthesis or Carol-Lee brackets parentheses
will create sub shell that those commands are.
Which is not always good as you will see later.
And at the end we will print that secret so we can print secret is that there is no secret save to file
ground.
Is it with permission
and then.
If you specify age 25 it works.
Bhakt when I put age for example 15 something went wrong.
I see all messages printed.
So what has happened here.
So I will open a script to show you that as I told you when we use parentheses comments are from in
subcellar.
Basically it means in another show an exit command only exited that shell and because thats actual written
exit's that was the one.
We also see the message of l.com because statements after double pipes are executed if exit status is
not zero.
So now let's change the script and instead of parentheses we will use Gardley brackets.
Here it is important that after first first Gardley break it to have space and before that last curly
break it to have a semicolon
Now you can save descript
and you can Adani
for age 25.
It works fine.
And for age for example then also fine b c you are not allowed to see this secret great.