 Hello and welcome! Today we're going to be looking at bash scripts and we're going to be looking at fallback variables. So you might be wanting to get user input from a user and you know sometimes if they don't give you input you ask them again but sometimes if they don't give input you're going to want to have the variable you fall back to. So if they just leave it blank you're like okay this is the default. So that's what we're going to do. I'm going to create a very script. I'm going to call it my.sh. I guess it doesn't matter and we're going to start off with the shebang line. Again the shebang line is just telling the operating system we want to use this interpreter. In this case we're going to use bash and of course we can say something like echo dollar sign 1. Just to review now we'll make that executable. To review this if I run my script now nothing happens it echoes out a blank line but if I say chris it says chris if I say chris john it's just going to say chris and the reason for this is dollar sign 1 is the first argument given. So we want to have a script that says hello whatever is given. So now I can run this I can say I'm chris and it says hello but if I leave it blank now it just says hello which is I guess still works in a lot of scenarios but let's just pretend it doesn't. We want to show a name and it's going to be whatever our default name is. So let's go back in here to our script and I'm using Vim as my text editor. I feel like free to use whatever text that you like as long as it's not like a word processor because that will screw things up. And what we want to do is we want to set our variable of name and here we're going to say echo name okay. So what we're going to do is we're going to say name equals and then we're going to say dollar sign curly brackets 1 colon dash and then here we're going to give a name I'll just say John okay. So what are we doing here? Here we're saying our dollar sign curly brackets um with the one is saying again it's just like before number one argument. It's saying okay we're setting name equal to whatever the number one argument is but if number one argument is blank filling John. So that should be all we should have to do now. Now I can run my script and I can type in Chris and it says hello Chris but if I leave that blank it will say hello John. So that will default to John if we don't give another name. Going back in here we can also ask for something. So here I can say use the read command dash P to print a message and I'll say how old are you and I can put that and then we're going to give variable of age and then we can say echo dollar sign name is dollar sign age years old and here if I run my script I can put in Chris and it says Chris hello Chris how old are you? I'll say 88 and I'll say Chris is 88 years old. If I leave that blank it will say hello John how old are you? I'll say 44 and it says John is 44 years old. If I run that and I leave my age blank now it's going to say John is blank years old and we don't want that. So going back into our script what we're going to do is here is we're going to ask them for their age but then we're going to check we're going to say age equals so we're overriding our age variable in whatever case it is and then we're going to say age colon dash and here we'll say 33 so now what's going to happen is I'm going to run my script if I leave the name blank it's going to say hello John how old are you and I can say 22 and it will say you are 22 years old if I run it and I leave the age blank it will now say John is 33 years old and I can give it a name I can say Chris and it says hello Chris you are how old are you and I can leave that blank it will say 33 but if I do this I can say 38 and it will put in 38 and of course you can do this for whatever variables you want and here we can also give another example we can say I'm just trying to think of another example if we want to instead of asking them for their age here I can change this $2 sign too so I can make the second argument checked there so now I can say my shell I can say hello John John is 33 years old if I say Chris now let's say hello Chris Chris is 33 years old and here I can say 88 so we'll say hello Chris Chris is 88 years old so I replace the second argument in that case and of course if they have want to give their full name we can say Bob Smith inside quotations it'll say hello Bob Smith Bob Smith is 88 years old but if I leave that blank it will say Bob Smith is 33 years old so I'm hoping this is making sense pretty straightforward because it's just the variable right in here and it's saying colon minus so colon dash and then whatever you want the default to be so if it's blank at this point it will be replaced with whatever is here and that is pretty much it that's creating fallback default variables so that if a variable is blank it will fall back to the defaults I hope you found this useful and as always I hope that you have a great day please please visit filmsbychrist.com that's Chris the K link in the description like share subscribe I'll check out my patreon in the description have a great day