 Okay, one of the things we've been looking at as I go on with these videos is get passing arguments or inputs to your Scripts, so let's do a very basic example from previous video I'll just go into this main.sh very very basic We could do dollar sign one for the first argument dollar sign two for the second argument So now I can run that script and I can say Chris and John and it says hello Chris Hello John if I get more than that It just ignores those if I don't give enough we didn't do any checks in this particular script So the second line is just gonna be hello blank And we went into more of how to check you know for the number of arguments this and that but you might be also familiar with Passing information like dash I for something and if you want something else to happen you can do dash R Whatever let's look at how to do that and I've written up a script here that will walk through and look at and Basically, we're gonna use what's called get ops which looks at those options And we're gonna use a case statement which I've done videos on the past which is a lot times used for menus but here we're gonna check what's past and Set values or run functions based on what is passed So I'm just gonna Vim into a Vim is my text there use whatever text there you like This check that sh so going up to the top It's a bash script and I have a main function that main function will call the check function And then it will also run something after that to show that stuff set here can go up here to go down to the bottom This is where we're calling the main function. We're writing it up top But we're actually running it down here this dollar sign at symbol basically if I wanted to And I should have went over this more in detail in a different in different video But we'll go back to our main script here if I wanted to I can instead I can go here I can say arguments like that dot and now I can say main John and Chris and it's going to print every argument So that's what the dollar sign at symbol does it prints all arguments. So what I'm doing here That's not that script, but the other script We're saying okay all arguments that are passed to our script now pass them to the main Function now I'll go back up to our main function here now We're gonna call the check function and I'm gonna pass it all those arguments This is one way to do it you can also just put all this you know at the top of your script But putting stuff in functions is a little bit cleaner so we're passing all those arguments to this check function and We're gonna set some local variables here opt-in opt and I and Then we're going to Go through a loop we're gonna loop through each one of these and see if they match The option passed so op gets is a function that's going to look at all those variables that start with dash So let's let's quickly look we have I see M and and backslash dollar sign Let's just run the script a couple of times and see what we get so I go check and I can do C Actually, it's dash C and so C is a good option. No input file. I can do was another one M It says M has been chosen again with no input file If I can do I I says no input file, but if I go I and say give it some text says You chose I input is Chris Okay, so and if I give it an option that isn't one of those options like H or anything else It's gonna print out our help function. We'll look at that more. So it's not just age But if I just do anything M is an option. Let's try K is not an option and I can do even You know options that are in there like C and M But if I have K in there, it's it's going to go through that and when it gets that option It's going to run that help function because it's like K is not an option Let's go ahead and look a little bit more at how this works again at this point After we run get ops and give it our options starting with the colon here and then other options now Why is there a colon here? Well any of these with a colon after it is Saying there should be some sort of argument after that switch So we're saying I which is looking for an input. It's looking for text after that. So that's why we have that Semi-colon there or not semi-colon but colon there So now and we're putting that into a variable called up and we're looping through it So now we're going to say, okay We're looking at each argument given and we're checking if it's any of these things and if it is Do whatever's after this if you've done case statements before this is a basic case statement We're saying, okay, if the argument as we're looping through is an I we're just going to echo out You chose I and then the next then a new command. We're setting a variable input equal to whatever argument So opt arg is whatever argument is put in the place of this colon here So we're echoing that out and then later on in the script down here We're checking our input and as long as input is not blank. We're going to print out echo out Input is input if it is blank if there's nothing in that variable. We're gonna print no input file Which in this case is just text. We're not checking for a file But lots of times that would be the name of a file and input an output file Now if it's C, we're just going to echo out C as a good option If it's M, we're gonna set M to true and then back up in our main function when we get out of this check function Now we're gonna say if M So if it's true, we're going to echo out M has been chosen But if it isn't set to true, it's just going to not print that If N is an option, it's just going to run the N function and funk which is down here And there can be any number of commands in this function And I'm just giving you different options on how you can use these here and then backslash a dollar question mark That's a question mark not a dollar sign It's going to run the help function which basically the backslash H is if it's anything other than those options It's going to exit or it's going to run that function in this case. I say exit Which is interesting because because if I don't do that exit will print the help function So if I get rid of that, so here's an example. I go through here and I say CKM, let's put a screen CKM C and M are options here. It's going to say C is an option It's going to help print our help file But never get to the M because we exit out before we get there if we go back in here And I remove this exit saying that it failed and And run that same thing again It will say C is an option print our help function Then it will print no input file because there was no input file and then it will print our function that happens when M is chosen So because I'd exit there exits out before I get there So all depends on what were things need to come in your script So this is just a very quick overlook on opt-get. I will we'll be using this in a future video That's why I want to quickly go over it I'll try to remember post this in Payspin and put a link in the description of the video if not you can always go to my website go to software My notes and search for get ops and you'll find this among a few other scripts where I use that so you can see different Examples of it. Oh, by the way that yeah this shift And is just shifting the index of what we're searching through in the get up. I believe yes So that is just a very quick very basic look over get up It might seem a little confusing at first, but really the majority of it is a case statement Which I should use case statements a little bit more, but they're pretty straightforward It's kind of like an if then statement, but with things in a list Like so and lots I'm case I use case for menus. We're here. It's not menu We're just looping through all the arguments or switches past whatever you want to call them There's probably a technically a difference and again the colon here is saying anything past after I it should be looking for an input And here we're saying you know input is just why I'm calling the variable you can call anything you want, but the the What's in this spot past the I is the opt arg? So it's the argument passed to the get ops function That's it again We're gonna be using this in a future video so I want to go over it real quick I do thank you for watching and I hope that you enjoy it I hope that you watch one of my videos and I hope that you have a great day Thank you