For loop scopes and another advanced level of scripting you are keep getting better.
My friends keep getting better.
The next script is you're going to run as four loops scripts for loops.
What they do is it keeps running until a specified number of variable.
For example if a variable is defined 10 then run the script 10 times or variable is green blue red.
Then run the script three times for each color.
So it actually simplifies your tasks if you wanted to for example create file files or 10 files then
you don't have to run the command again again again fool for loops.
Will do it for you.
We all go back into our Lankes machine and we'll try a couple of scrubs for loops and then you can try
on your own and you will become proficient.
We're running these little little tiny tiny scraps which dirty we are when we are in our home directory
always home is not just home but entire home directory.
And the dirty that we are in is my script.
So in my scripts we're going to create a new script we're going to call it this time ABC do VI ABC and
the first thing you know already by now is that you define the shellscript that you're going to run
this script in or the show environment.
I would say that you're going to run this script.
And again I have already written a few script for you to go on this training and I'm going to go into
our first group which is a simple for loop output.
I'm going to copy the script and I'm going to just simply paste it.
This already has a defined shell so I'm going to delete that line.
So what is it doing for I in 1 2 3 4 5 do.
So I hear is a variable which is telling that this container which is the container name is why it holds
the numbers one two three four or five.
And then what he's asking you to do the script is going to do echo.
Welcome variable one time variable to time to wearables three variable for a variable five times.
And then once it's done it is done.
So that's why we have to define done at the end for the for loop to finish doing what is doing.
So I'm just going to save the file once a file save.
Again you have to give executable permission the permission is given.
That's verified.
Yes the ABC file is there that see what's inside of it inside if it is exactly the same thing.
Let's run the script ABC and there you go.
It's doing will come one time two times three times four times and five times.
So basically if you have a repetitive task and and trust me you're going to be working in IT in a corporate
environment where you would have to do so many repetitive tasks.
And this loop's group is going to become so handy for you that you will be creating scripts for every
repetitive task that you will be doing every day.
So this is outputting five times.
Let's look at the second script.
So the second script what is doing.
It's basically doing the same thing but this time it will just output the names and I'm going to make
this X Y Z as the name of the file and it has always starts with the shell the shell name has been Bash
and now this time we're going to put in some comment.
We're going to say this script will output
I'll put them on read different actions because it will say See Imraan eat see Imraan run see Imraan
jump and see Imraan play.
So this is what the script is going to do.
So that's why I have put it in just a comment.
You can put in more comment that say the script is created by Him longline have though and if you put
a date you can't get that up and the script starts right here.
But it's telling you for I in again I is a variable in is you putting inside of your variable and variable
it's just like a container.
It's telling you put.
Eat.
Jump.
Run.
Play inside of a container called Eye.
Once it has all these three or so four words inside of the container I then do what we are doing we
are echoing see Imraan dollar eye.
The variable is aurat always be displayed with the word the dollar and the name of the variable.
So it's telling its dollar eye.
And then once I once the is going to display every little every word in the container then it's going
to be done and done.
The script is created skimpiest done its job.
And we will verify it.
The script is there.
Next thing you'd know by now is to change the permission on the x y z so it will have executable permission
and executable permission.
Once again I am reiterating again and again if you can run the script it's because you do not have executable
permission.
So we do have a single problem executable commission.
Awesome.
Perfect.
Let's run it.
X Y Z Oh it's.
BASH X Y Z.
No such file or directory.
Why is that.
Of course we have put C Z actually x y z.
So let's run it and go see him run eat see him run run see him run jump see him run play.
So again it is doing repetitive tasks for you.
So the for loop is a very strong statement in a scripting environment that lets you run a repetitive
task again and again so you don't have to do it yourself and spend time all day and creating those little
tedious task.
I want you to write the scripts that I have inside of this file.
This file is again in your hand outs.
I want you to download this hand out.
Create these little scripts again and run it and see what they do.
It will be a great exercise for you.