 Welcome again. We're continuing on our shell script tutorials for 2017. These are, I wouldn't call these advanced tutorials, but they're intermediate tutorials. I do have plenty of tutorials I've done over the years on beginner stuff. This is going to be a little bit of a re-review, working with functions and shell scripts. It's something that I really should do more often. I very rarely actually write functions in my shell script, and lots of times if I did, it would probably make things a little cleaner and easier. Let's go ahead. I'm going to use Vim as my text editor, but use whatever text editor you prefer. I'm going to go into Vim, and we're always going to start off with our shebang line. Oops, if I could type today bin bash. This is just telling the computer what interpreter to use, because there's different shells. If you don't give it that shebang line, that first line saying use the bash interpreter, it's going to use whatever is default on that system, which may act different than bash. That's important, because the default on my system is not bash, and there are some differences. Although I write most of my scripts in bash since that's one of the more common ones installed on systems by default. Moving on, we're going to create a function. I'll just call it main1. Now we can put stuff in here. I can say echo test echo this is function1. There's a function, and now I can call it just by calling it main anytime I want. If I save this, make it xcubal, which we just have to do one time on our system. It's just giving that script permission to run. It's a security thing to make sure that programs just don't run without your permission on your system. Then I'm going to say dot slash dot slash just means in the current directory run this, because there might be a system-wide program called functions.sh, which would run before this one. So you've got to tell it in this folder run this script, rather than one that you've installed to your system. So I'm going to go ahead and run that, and I have a little typo there. I didn't call my function main, I called it main1. So let's try that again. I'll save it, run it again, and then we go, you can see test this is function1. And if I go in here, I can copy this line a couple of times. We'll copy it four times, and if we run it, now it runs that function four times. Let's make a second function. We'll call it main2. I'm going to say echo main2 echo this is another function. We'll go ahead and save that. Oh, be good if I called that function. If I run it now, it's not going to run that function, because we've loaded it but we didn't run it. But let's go ahead and do this. I'm going to run the main1 function once, then main2, and then main1 two more times. Go ahead and run that right there. And there you go. You can see it ran the first function, the second function, and then it ran the first function two more times. Now let's add variables to the situation, because that's where functions really start to become handy. So let's make another function. I'll call it, I'll just call it main3, whatever. In real life, you should want to name your functions, something a little more useful than that. What I'm going to do in here is I'm going to say echo the person is, and I'll say dollar sign one. And I'll say echo dollar sign one is a good employee. Now, I can call main3 down here, but I've got to give it some input. Here we're looking for a person's name, so I'll say Tom. Now, if I run this, you can see it runs our first few functions, and at the bottom here it says the person is Tom. Tom is a good employee. So it's useful about this, and we're doing a basic example of echoing something out, but you can put these variables into more elaborate functions that do a lot of stuff with them. But I can paste that a few times, and I can say run, let's space there, Tim and Bob. And now I can run this, and you can see it says the person is Tom. Tom is a good employee. The person is Ron. Ron is a good employee all the way down through Tim and Bob. And now you might be thinking, okay, what is the one? So you can pass it many different variables, and just as you can pass variables to your script itself, the variables are numbered. So if I was to come in here and I was to say Tom Smith, Ron Carpenter, Fisher, and... Why can't I think of a name? Jones. There you go. Now, if I do that, you're going to notice it doesn't print any of those last names. It's still only saying the first names. So what can we do here? Well, if we want the first and last names to be into separate variables, we can do that. If I wanted to, I can say the person is Tom Smith. Tom is a good employee if you don't want the name the second time. So we'll run that and you can see the person is Tom Smith. Tom is a good employee. The person is Ron Carpenter. Ron is a good employee. The person is Tim Fisher. Tim is a good employee, so forth and so on. Or what I can do, if I wanted it to display it all together every time and I'm not going to want them separate, I'm going to want the last name and first name always together, what I can do is I can put... Let's see. That's not really what I want to do. Like so. So now, since I put quotations, just like we talked about in the arrays in the last video, these are considered one item, one set of information. So the number one is going to be the first name and last name. So now I can run that again and you can see the person is Tom Smith. Tom Smith is a good employee. The person is Ron Carpenter. Ron Carpenter is a good employee, so forth and so on. So that's just a quick look at functions and passing them variables. And we're going to actually use the arrays from the last video and the functions from this video to build upon in the next video. So as we make a little animated spinner for our scripts. I thank you for watching. Please visit Filmspy... Filmspy? Filmsbychris, that's chris-the-k.com. There's a link in the description as well as a link to my Patreon page. There you can sort me for as little as a dollar a month is helpful or it would be even better. There's also, if you go to Filmsbychris.com, there is a link where you can donate through PayPal. I want to thank you for watching and as always, I hope that you have a great day.