hey guys welcome to the next blog on shell scripting tutorial for beginners in the last blog I've shown you how to use the while loops in shell scripting now in this blog I want to continue using the while loop and I'm going to show you some more tricks which you can use with value and the first trick is using sleep with the loops right so as you know this code I have written in the last video and this prints the value 1 to 10 on terminal right now for some reason I want to give some delay while printing the value and this I can do with sleep command so I can just write sleep here and then whatever number I will give you for example 1 it's going to pause the execution of this loop for this much amount of seconds and once again executing this loop normally right so the sleep command gives a pause or for whatever seconds you want you can write here so if you want to seconds you can write to second or whatever seconds right so let's run the script and let's see what happens now so run the script and you can see the numbers are printing after interval of one second and once the condition is met you can see it comes out of the loop and we can see our normal terminal right now if I don't provide this increment the value of n will always be one so for example I remove this increment of n the value of n will always remain one for example and this loop will execute infinitely so let's run the script and let's see what happens now so you can see it's printing 1 1 1 1 and this condition is always true so this script will run always until you stop executing it right and how to terminate this process is running using this shell script you can just press control-c to come off of this script so ctrl C and I'm out of this script okay so if you want the continuous loop you give a condition such that it's always true right but always remember that you know whatever is the logic of your code if you do not provide this sleep this loop will work infinitely and it will run so fast that it may you know slow your computer even sometimes right so this is the first trick now the second trick I want to show here is how we can open some terminals so for example I want to open three terminals so I will just write instead of ten three here and I want to open a terminal using my bash script right so what I can do here is depending upon the what kind of terminal available on your operating system you can open those terminal so on my open two operating system I have X term for example and genome terminal which is this terminal this is the genome terminal and X term is also available on my system so let's use the genome terminal command to open those terminal first
so I will just use genome - terminal and just give this and single after this right and let me clear the terminal first of all and let me choose run the script and you will see three more terminals are open so there is the first I will close this the second once again close this and the third I will close this right so using this genome terminal command you can open the normal tunnel like this and X term is available also on my Ubuntu operating system so instead of genome I can just write X term and then once again I will run the script and you can see these terminals are open three terminals right so I can close them once again so these are the two traits I wanted to show you in this blog and in the next blog we will see how we can read a file using while loop so stay tuned and i hope you enjoyed this BLOG 😊
Post a Comment