 Hello and welcome. This is, you know, we've just started a series on shell scripts for 2017. We're going to be doing a lot of these and we're going to do a lot of short tutorials and build upon them. And today we're just going to look at arrays in a way. We're going to look at just looping through an entire array. So let's go ahead. I'm going to use them as my text there but as always use whatever text there you're comfortable with. And I'm going to start off by using, giving it the shebang line, bin bash. Now let's go ahead and create an array. So an array in bash is pretty simple. We got to give it a name. I'll just call it array here. Of course in a real script you want to give it more of a name that tells you what it is. And here we can give it things like dog, cat, bat, mouse. And that is our array. And we can call it, you know, if we wanted to echo it out, we could do something like this. Echo, dollar sign. And then inside these squiggly braces or curly braces, whatever you call it, we'll call array. And then we'll give it the number of the array we want. So we have these arrays here. I'm going to put in one. I'm going to save that. Now it's a shell script. We have to make it executable. Give it permission to run. We only have to do this once on our system. Once we do that, we do dot slash, dot slash again just means we're running a script in the current directory, not a system program. From our path directory. So let's go ahead and run that. And as you can see, we got cat. Now you might go, why didn't it do dog? Because arrays start at zero as they should. So if we want a dog, we can say zero. And of course we can go in there and I'll copy this line. And I can do two, one, or two, three, one. Oops, let's go ahead and fix that. There we go. So it should go dog, bat, mouse, cat. If I'm looking at that correctly, run it. There we go. Now, let's say we wanted to loop through all of them. We want to do something with each of them. We can do this. Let's go ahead and delete these for the most part. We're going to create a loop, a for loop. So I'll say for and then a variable and give it any variable. I'm going to go with i, which stands for integer. We're going to go through each one of these things. And we're going to go like this. And we're going to say in here, we're going to give it our array, which was array. And inside our square brackets, instead of getting at the number, we're going to say at symbol, which just means display all. Actually, before I do that, let me show you that by itself. So here I'm going to say the outside of the symbol. So instead of echoing the number, I'm saying echo at. And now if you run this, you can see it prints out all of our array. All four items. But what we're going to do here is we're going to say, OK, for each item in this array, so each one of these, put it in this variable and do something with it. So down here, what we're going to do is we're going to say do this and we're going to say done. And that will loop through that. Whatever we put in here, it will loop through. So we're going to say instead of echo array here, we're going to say echo dollar sign i. What this is going to do is, like I said, it's going to loop and it's going to go dog, cat, bat, mouse. So I can do this and run it and you can see it does that and we can add things to our echo command here. I can say it is a, and when we do this, we'll go through it is a dog, it is a cat, it is a bat, it is a mouse. And if we wanted to put a little delay on there, we can go sleep and we can say 0.2, so just less than a quarter of a second and you can see now we got a, it prints out and says just displaying them all at once, it goes okay. So from here, what we can also do, I want to show you, let's say I wanted to say little cat. Well, obviously I couldn't just go like this because if I do that, it's going to put little and cat as different items. So you'll want to put those in quotations and really it's a good idea to do that. Even if you don't have to, I like to put quotations. Sometimes it's overkill but sometimes it will help prevent errors and mistakes like that. So I don't have to put quotations around all of these, only the ones with spaces in them. But let's go ahead and run that again and you can see that did not work. Let's try this, single quotes, I think that will work, nope, let's try one other thing. Well actually, I think I realize it now. Let's see if I'm right about this. I should have put quotations around this part. So let's try this again. Let's go ahead and remove all our quotations like this, well I guess I could have left those. So we're still going to see little and cat on separate lines here. And now if I put quotations, and I'll explain why that is in a second, there we go, now we've got little cat. So this will divide this up and I've got to put quotations around each one of these if I want, single or double. And they will be separate items in the array but when we're doing the for loop, the for loop again is looking for spaces. So if we don't put quotations around it here, it's going to see even though it's passing one item, the for loop is going to see it as two different items. So that's a little mistake on my behalf, easy mistake to make. Again, there are a lot of situations where you don't need quotations but in most cases I put them all the time just to be sure and again this is one time I didn't do it right here and I should have and there was an example of a mistake. So let's go ahead and run that again. So again I don't need quotations around the single words but it's not a bad idea to have them there. So this is just a quick look at looping through arrays with a for loop. We're going to build on this as we go on in the future tutorials. So thank you for watching. Please think about subscribing if you do like my videos. Also visit my channel FilmsByChris.com that's Chris the K. There's a link in the description. There's also a link in the description to my Patreon channel if you want to become a supporter over there. I hope that the dollar a month is helpful. I appreciate it and as always I hope that you have a great day.