hello guys welcome to the next blog on shell scripting tutorial for beginners in the last blog we have seen how to use and logical operator with scripting now in this blog we will learn how to use or a logical operator encrypting so let's get started so if you understood the last concept of n the logical operator it's really easy to understand our logical operator so we will take the example which we have taken in the last blog and we will you know have the students age or anybody's age here in the age variable and then we will just evaluate that age if the age is greater than 18 and in the last blog we have seen and with the end operator we have added one more condition that if the age is less than 30 then we will say it's a valid age or it's not a valid age now this time for example we want that if the age is greater than 18 or age is less than 30 then we will say that ages are valid so instead of using the and operator like this we can just use double pipe to you know use the or operators right so we will just take these square bracket and in the first square bracket you can give the first expression and then these two pipe for or operator and then use the second expression which you want to evaluate now this or if you already know is for logical or so if any of the condition separated by these pipe is true then it's going to give this valid age otherwise it's going to give the other condition which is an else statement if both conditions are false then the code will go to this condition or as statement okay so let's run the script and let's see what happens so our age which we have given is 60 so in this case the age is greater than 18 because 60 is greater than 18 but it's not less than 30 so only one condition is fulfilled and then we will just run our script and we will see what happens and it says something is missing yeah I forgot this space here and once again I'm going to run this script at face valid age because one condition is fulfilled and other is not right now for example we will just give some current some age in which both conditions are fulfilled you will still get the same answer or result they say it's valid age right now for evaluating the false current condition or to you know come into the as condition for example I gave the age 25 here and instead of for greater then I will use equal to here and equal to here okay and then of course the age is not equal to 18 and of course age is not equal to 30 because it's 25 and let's run the script once again and it will say the age is not valid and it also gives me the warning that this square bracket has some problem in it so we will solve it by giving the space here once again and then once again we will run the script and it saves age is not valid right so this is how you can use or operators and of course as an operator the or operator also have some options so if you want to use the of or operator with one bracket and not two bracket you can just use - Oh for or operator and the result will be same so let's run the script and the is the same so you can use double brackets and those two pipes for the or operator or you can use this flag - Oh for the Opera auto operator with single square bracket and the last way you can use this is using the double square brackets and in here you just need to give double pipes once again as you have seen in the end operators also and the condition still will be the same okay so as the end logical operator you can use the or logical operators also in three ways one is with two brackets and these pipes and other is with the flag and single brackets so - oh flag and this single square bracket or otherwise you just need to use double brackets with the or operator pipe so you just need to write something like this and between the two square brackets you can give the pipe or for all operator okay so I hope you enjoyed this blog
Post a Comment