 Hello and welcome. Today we're going to be looking at passing arguments to our shell script. I'm going to show you some basic stuff right now that I've probably shown in the past. But then in next couple videos, we're going to take it a few steps further. There's different ways to pass stuff. We're going to look at piping stuff into a script and having different switches and arguments that you can pass to your scripts. But let's right now just create basic script and show you how you can put information in there. So I'm just going to call it main.sh and here I'm going to say, let's give it a shebang line of bin bash. And what we're going to do is we're going to just say, we'll say hello. Okay, we'll make that executable. And we ran it with dot slash again dot slash just means the script is in the current directory, not the system path, and it prints out hello. But let's say we wanted the user to, from the command line, as it runs a script, give it their name. So we can go into our main script here. And the way we can do that is we can put it right in here, should be able to put it right in here, dollar sign one. So when you pass arguments to a script, each argument that is passed is given a value of a number, dollar sign, whatever. So now if I run main like this, it still says hello. But if I say my name Chris, now it says hello, Chris. Now, what if I say hello, Chris, and John, how about that? It still just says hello, Chris, because it's looking at each one of these as a separate argument. One way around that is I can put this in quotations. And now it's going to see this as one argument. Now we'll say hello, Chris, and John. But let's say you wanted it to print all of that. Well, one way, you can come in here and say dollar sign two, dollar sign three. And if we run it without the quotations, it's going to say hello, Chris, and John. If we do it with quotations, it's still going to print hello, Chris, and John, because it's printing the first one and the other two are blank. But that's kind of a sloppy way to do it because you don't know how many arguments they're going to pass to it. So what you could do is put an asterisk, which means all arguments passed. So now I can say hello, Chris, and John with the quotations. I can say hello, Chris, and John without the quotations. And I can just type more things and it's going to pass all of them to there. So that's one option. But of course, you can write your script if you want to have it. One, echo, hello, dollar sign two. Now I can pass it like this. I can say, you know, give it a bunch of names. I can say, Chris and John will say hello, Chris. Hello, John. But of course, if I give it a fourth name, Bob, it's not going to do that because we're only passing it to two variables. So what you could do is you can make a while loop that loops through each argument. You can also check the number of arguments. So let's say we want to require them to have two arguments. What we can do here is we can add an if statement. So we can say if, and what we can say dollar sign pound, or also known as number sign, also known as a bunch of other things, hashtag. But what we're here is we're saying is dollar sign, of course, is a variable. Here we're saying number. So we're saying that's passed the script. We're checking the number of them. And then we can say dash LT. We're saying if it's less than, and we'll say two, then, and we'll close our if then statement, we can say echo two names needed. And then we can always say echo example. And you might think, okay, dollar sign one, what about dollar sign zero? Well, dollar sign zero, as I mentioned, is the name of your script. So basically, when you type something, this is argument one, argument two, argument three, and this is argument zero. So that makes sense, right? So what you can do here is as an example, you can say dollar sign zero, I've mentioned this in previous videos, will give you the name of your script. And that way, no matter what your script is named. So like, let's say I named my script. Hello's. I wouldn't want to put that in here as that because if someone renamed the script, well, now it's not making sense to the person running the script. But if I do dollar sign zero, it doesn't matter what you name the script, it will print that name there. So dollar sign zero, Chris, John. So now, oh, and then we want to also exit. And that would exit a script. We want to say exit one. So exiting zero will mean that the script was successful. Saying exit one is saying, well, the script failed. And you can check that if you're calling this script in other ways. And if it fails, you can do something. And if it succeeds, it does something else. So now, if I run my main script, I do this, I didn't give it any names. It's going to say, Oh, you need to give it two names. And if I give it one name, Chris, it's still going to tell me you need two names. And so now I can say Chris and John. And if I give more, it's, you know, above, it doesn't matter. But you can also check, you know, if they have more. So if you want them to not have any more than something, you can also do, you know, if it's greater than so if the number is greater than do something. But you can have different options in there for that. So that is one way to do arguments. And that's way for a lot of simple scripts you can do. But sometimes, like I said, you're going to want to pipe information from one program to your script, or you're going to want to also have switches where maybe you, you want different arguments, but not in a certain order. So that's when you have, you know, dash i for input dash o for output. So we're going to look into those options in the coming videos. So I do thank you for watching. Please visit filmsbychris.com. That's Chris the K. There's a link in the description as well as link to my Patreon page. You can also go to filmsbychris.com. Go to the sports section to support me through Patreon or through PayPal. I do appreciate your support. And you also get early access and downloadable videos. So you don't have to wait for the next videos to come out. You get them fairly quickly after I make them. And also go there to search through all my videos from both my channels. I do thank you for watching as always. I hope that you have a great day.