this BASH script will KILL you.

Video Notes:

Build your own Elden Ring with Linode: https://ntck.co/linode and you get a $100 Credit good for 60 days as a new user!

In this episode of the BASH scripting series, NetworkChuck covers BASH conditionals and harnesses this power to create Elden Ring inside of a bash script. Along the way, NetworkChuck also covers nested conditionals, or nested if statements, as well as elif and case statements.

🥇🥇Become a BASH MASTER with extra labs and quizzes: https://ntck.co/BASH

🔥🔥Join the NetworkChuck membership: https://ntck.co/Premium

**Sponsored by Linode

0:00 ⏩ Intro
0:29 ⏩ the challenge
1:50 ⏩ Sponsor Message
3:24 ⏩ Elden Ring Script Setup
4:05 ⏩ Bash Conditionals (if statements)
7:58 ⏩ Elden Ring Bash Conditionals
13:40 ⏩ BOSS BATTLE (Using OR in bash)
15:39 ⏩ other options in Bash Conditionals
19:22 ⏩ Nested IF Statements (Bash Conditionals)
21:33 ⏩ ELIF statements
23:53 ⏩ CASE statements (a switcher)

“Elden Ring” But in a Bash script. That’s what we’re building today. You wanna help me build it? Let’s build it. Get your coffee ready and prepare to die a lot, but also learn a lot. We’re gonna level up our Bash skills and build “”Elden Ring””, one of the most popular games out there right now, inside a Bash script. Let’s do this. Now, honestly, building “”Elden Ring”” inside of Bash script is gonna be pretty easy. In fact, you could probably do this right now in about 30 seconds. Here’s the task I want you to try and accomplish right now. Now, if you’ve been watching this series, this’ll be pretty familiar. First thing you wanna do is create a script, name that sucker eldenring.sh and prep it right. You know, make it executable, add a shebang, you know, all that stuff. And then for number two, which is really the last step, just echo or print out in the terminal “you died”. And that my friends is “”Elden Ring””. Pause the video and do it real quick. Un-pause, coffee break. Told you it’d be easy. Now, seriously, if you played the game “Elden Ring”, this is what you see a lot. You die a lot. Yeah, there is a bit more to it. And don’t worry, we’re gonna add more to this script. And warning, you’re gonna learn a bit more about Bash scripting here in this video. You’re gonna learn about conditionals and how we can kind of gamify our scripts. It’s gonna be fun. And also another warning, this can get really crazy, really addictive. I apologize to your family and friends. You’re gonna be doing this for the next like 12 hours, just like “Elden Ring”. So let’s do this. Now, first of all, if you do this by yourself, congrats, that’s amazing. You already have some solid Bash scripting skills. If this was hard. Go back and watch the first three episodes in this series and come back and see me. So now real quick, let me walk through what I just asked you to do, and then we’ll build on that knowledge and do something crazy in our Bash scripting. So first I need to fire up my lab. You were probably wondering Chuck, how am I supposed to do this without Linux? I’m like, you know what? I got your back. Here we go. Check the link below in the description or navigate out to limbnode.com for like, ah, can’t talk today. /networkchuck. See, I make mistakes all the time. You just don’t see that, I edit it out. Nick, edit out the mistakes please. Well, Linode is my cloud provider. It’s what I use to do labs and all kinds of stuff in my business. And I love it because it only costs me one penny per hour. I’m not even kidding. Let me show you real quick and feel free to follow along with me as you set up your own lab. Once I’m logged in I’ll click create a linode, images, I’ll do Ubuntu. Region: Dallas. Linode plan: I’ll do it, Ninode, one gigabyte. Label it and put in a password. And then create woo. That was fast. And now my magical Linux box in the cloud is baking, it’s provisioning and it’ll be up in a few seconds here. And the cool part is once I’m done on my lab, which will be pretty soon. All I gotta do is go over here, click on the dots and say delete. And it’s gone forever. It’s not charging me any more money. It literally will only cost me a penny for that hour. And also if you’re new to Linode, you never heard about it. You get $100 credit for the first 60 days for free. So if you heard free, Linux lab in there, go with that, ’cause that’s what it is. Link below. And let’s see if mine has done baking, still baking right now. And legit, I use Linode for everything. You may have seen before, I have like a bajillion virtual machines that help me run my business inside Linode. So if you are running a business, check ’em out. Or if you’re doing any crazy projects like I do all the time, also check them out. I run too many. Anyways, my box is ready. I’m gonna copy my SSH access stuff over here and launch command prompt here in Windows. Or if you’re using Mac or Linux, it’ll be terminal. I’ll paste that command, hit enter, accept all fingerprints, and put in my password, and we’re in. Okay, let’s get started. Let’s go ahead and knock out step one. Nano eldenring.sh Shabang! Did I scare you? I’m gonna get you one of these days. Comment below if I scared you. Shabang in place, I’m gonna do control X, Y, enter to save it. Let’s make it executable real quick. Chmod+X eldenring.sh Done. Let’s verify ah, on command again, I did it again. Now, it looks pretty. There’s that X. Now let’s get back in the script. eldenring.sh and with one command we can complete our “Elden Ring” game. Echo. That’s it. Control X, Y enter to save and let’s run our script right now. ./eldenring.sh You died. That’s the game guys. I hope you enjoyed it. Let’s play again. Woo! What a fun time. But seriously, let’s Bash this up. Let’s make it crazy. Let’s learn a new thing called conditionals. It’s a very boring name for something that’s very, very fun. They’re also referred to in other languages and just colloquially around as if statements. I always struggle trying to say colloquial, colloquially. I still can’t say it. I’m not even sure how to say it. I’m gonna give up. If statements. But conditionals and if statements are powerful because they give our scripts the power, I’m saying power a lot, to make decisions, kind of like AI, like robotic. It will make decisions and change its behavior based on what we program here with these conditionals and if statements. Allowing us to make a pretty sick game. And yeah, it sounds amazing and honestly kind of scary. Let me show you an example. Let’s jump back into our “Elden Ring” file. Nano eldenring.sh and right after you died, let’s do a little coffee scenario. I’ll do an echo and say, hey, do you like coffee? Do you like coffee? And they’ll do like a parenthesis y/n. So we tell ’em, hey, we want a Y or an N, a yes or a no. Then real quick right here, I want you to get that data, read that data, and put it inside a variable named coffee. Pause the video and go. Unpause. Coffee break. To do that, we’ll simply type in read and then coffee. This will prompt the user for input store that input inside the variable coffee. Now here comes the fun part, the decision making, the craziness. Track with me here. Here we go. Type in if. If is one of the most powerful words ever. I love it. Especially in programming. If, this might get a little weird, don’t worry. We’re gonna stay together. Do bracket bracket, opening bracket bracket. That felt weird to say twice. Then let’s do a space. Now let’s reference our variable coffee. I’ll say $ coffee. And then we’ll type in equals equals space and let’s type in the string y. So Y between quotations. And then, I know this is feeling weird. You’re like, Chuck, what am I doing? Put a space and then closing brackets. Two of those suckers. Closing, closing. What’s going on right here? Here, we’re telling the computer, we’re telling this Bash script to evaluate something. We want you to see, Mr. Bash script, if something is true, is this true? And that’s essentially what a conditional or an if statement is doing. We’re saying, hey, here’s some data Tell me if that’s right, like let me know. And then do something with that. Like watch this. So here we’re saying the variable coffee, if that equals, and that’s what we’re doing with these equals signs, we’re saying equals equals. We’re saying if they equals the string Y, do something with that. If that’s true, do something. So let’s make it do something. So just after the last double brackets, we’re gonna do a semicolon, or semicolon, space and then type in then hit enter. So we’re saying, if this is true, then let’s do something. Now here to make things clean and pretty I’m gonna hit tab. You don’t have to do that, but it makes it feel nicer. Helps us understand what we’re doing better. You’ll see. Type in echo you’re awesome. And then hit enter. And now do this. I want you to type in the word else. Else, hit enter. We’ll tab out again. Let’s echo leave right now. Okay. And then finally hit, enter and type in fi. Just like this. If backwards, if in reverse. So what’s happening here is incredibly powerful. May not feel like it yet, but it’s gonna get crazy, but here’s what’s happening. We’re saying, hey, if the variable coffee equals the string Y, ’cause that’s what it’s gonna end up doing if we answer it correctly. If it does then print out “you’re awesome”. Else. Else, if it doesn’t equal that string else leave right now.

– Leave, now.

– Are you seeing how powerful this is? We can tell our script to evaluate something if it’s true or not, and then do something based on that information. Let’s run the script real quick. Here we go. Let’s control X, Y, enter to save. And let’s run that script. Eldenring.sh You died. Hey, a weird way to start the coffee shop situation. Hey, do you like coffee? Let’s type in Y. You’re awesome. Now let’s try the other one. I’m I’m even hesitant to do this. So run the script again. You died. Hey, do you like coffee? Let’s type in N. Leave right now. That’s the appropriate response, I agree. Look at that. With this conditional, or if statement, we change the behavior of our script. Now we’re gonna harness that power to create “Elden Ring”. It’s gonna be fun. Okay, let’s do this. So let’s jump back into our script. Nano eldenring.sh I don’t believe there is any coffee in “Elden Ring”. There should have been. So we’ll take all this out. That was just for fun. We’ll keep you died, though. That’s accurate. Because that’s what “Elden Ring” is. It’s all about fighting things and dying from fighting those things. So let’s make that happen right now. Now this is gonna be cool, ’cause it’s gonna use an element from our previous video. This is gonna use random, or random variable. Actually let me draw this out. ‘Cause I’m getting way ahead of myself and getting too excited. Here’s what I want to happen. We, us, with our coffee, ’cause there’s now coffee in “Elden Ring”, I said so. I need eyes. There we go. We approach a beast. Will we vanquish this beast? Or will we die? We have to decide that. And actually we’re gonna have the script decide that. So we get ready for our attack and we’ll have the script ask us, or make us choose, a number between zero and one. So we’ll pick that zero or one. And then we’ll also have the script, the machine, the beast itself pick a number between zero and one. If our number, let’s say we pick one, matches the number that beast selects, let’s say it’s one. Then we win. We are victorious. So this gives us a 50/50 chance of vanquishing this first beast. Now this is an easy battle, but we can still die. But anyways, let’s do this logic real quick. Let’s walk this out in Bash scripting. First let’s add comment, keep things clean and documented. First beast. Here we go. Now first, if you have an idea of how this should go, go ahead and try it real quick. We’ll walk through it together, but I want you to give the good old college try. Nevermind, I hate college. Give it the good old YouTube try. Pause the video. Unpause. Let’s try it out. I’ll first create a variable and I’ll call this beast. Now, by the way, this there’s probably a few ways to do this and I’m just gonna do it one way, my way. So I’ll create a variable called beast and I’ll have that equal the random number the beast will come up with. I’ll do a $ and double parentheses to tell my Bash script, hey, I’m about to do some math, buddy, an arithmetic expression. Put a space there to make things clean and I’ll call my variable random, do modulo and I’ll type in two. That is not modulo that’s a random sign. I mean that’s the ampersand. I am not okay. There we go. And two. And then closing parentheses. You may recall from a previous video that using the random variable combined with modulo, we’ll give us the random number in a range we specify. Here, we’re saying give us the numbers zero and one, the first two digits. And that’s that. That’s what’s happening. So cool. Now let’s get our number. So let’s echo something really scary. Your first beast approaches prepare to battle pick a number between zero and one. It’s hard to make that sound menacing, zero and one. Then I’ll do a parenthesis zero one. So like you can know, oh yeah, select. Okay, cool. And we’ll put this inside a variable named tarnished. That’s what they call the characters in “Elden Ring”. You’re tarnished. So that’s gonna be our attack, tarnished. I won’t get too nerdy on you unless you want me to. I don’t know. So at this point we’ve got our beast number. We’ve got our number, our attack number. Now let’s do some conditionals, some decision making off of that. So let’s type in if, it all starts with, if. Unless we do something else and I’ll show you that in a minute, it’s even cooler. Okay. Calm down, Chuck. If bracket, bracket, opening bracket and we’ll call the variable beast, call the beast. If beast equals the variable tarnished, that’s our statement that we want the Bash script to evaluate is this true, closing brackets. We’ll do our semicolon and then type in then ’cause we’re ready to evaluate the next thing or because we’re ready to take the next action. Then do this thing. Let’s do a tab just to make it nice and clean echo, beast vanquished. Congrats, fellow tarnished. That’s just verbiage I feel like is from the game. Anyways, so that’s what happens when you win. Hit enter, let’s do an else. And then you probably saw this one coming, echo, you died. And that’s it. Now I’m forgetting something. What am I forgetting here? Fi. You’re exactly right. Forgot the fi. Oh, not right there. At the very end we have to close this out. Fi. Otherwise it just will not work. We’re telling these script, Bash script boss here, that the conditional is over with fi. It’s finished. So now let’s test it out. Let’s do control X, Y, enter to save and let’s test out our “Elden Ring”. Let me clear my screen here and let’s run our script. First, we died. Expected. Your first beast approaches, prepare to battle. Pick an number between zero and one. Zero. Here we go. I died. Dang it. Okay, let’s try it again. I’m feeling zero again. Take that beast. Let me know if you vanquished. Did I spell vanquished, right? Let me know if you vanquish the beast on the first try. Let me know how many tries it took you. Ah, I won. Now, that was great, but honestly it’s a bit too easy for “Elden Ring”. So what do you say to create our next battle? Our next beast to come at us. And this time the beast is way more powerful. We have a much lower chance of winning. So I want you to do this actually. So the next beast is coming up. His name. Let’s name him. Some of you may recognize this from the game. His name is Margrit. Which as I say, that doesn’t sound very menacing at all, but it’s spelled like this. It still doesn’t make it seem scary. Here’s a picture of him. Nick, put a picture up. Is he any scary? Okay. So I want you to battle Margrit. Is it Margit? I think it’s Margit. Let me Google it. It’s Margit. Which for some reason dropping the R makes it sound scarier. But according to Dwight, that’s not true. But anyways, I want you to battle the beast Margit. But instead of having a 50/50 chance, I want a chance one out of 10. Do that right now. Pause the video. Unpause. Let’s do it real quick. Coffee break. Let’s get back into our script. Nano eldenring.sh So here, just under our first beast battle, I’m gonna sleep for a bit. Give some time. Sleep two. Let’s bring our next boss. Echo, actually, yeah, this is a boss, a boss battle. Boss battle. Get scared. It’s Margaret, Margit. Pick a number between zero and nine. Now I said one in 10 chance, that means zero, I dunno, I’m holding it like this, zero to nine. That’s 10 digits, zero and nine. And I’ll do like a little parenthesis saying zero through nine. I guess I don’t have to do that. I’m just gonna do it. Cool. Now let’s read that data. Read. And I’m gonna type in tarnished. And yeah, in case you’re wondering, I just did reuse that same variable. I’m just reassigning it. You can do that. And now let’s do our beast. So I’ll use the same variable again. Beast equals, and we can pretty much just copy the code up here. Let’s go ahead and do that and be lazy. Come here code. Paste that right here. And I’ll change my two to 10 Giving us the first 10 digits, zero through nine. Okay, cool. And then let’s do our if statement. We can pretty much just copy this up here. Oh, one more thing. Up here where you died, if you do die, let’s make sure you just can’t like waltz out of there. Let’s type in exit one. This will actually make you exit the script with that exit code and you’re done. You have to restart the game. So that’s good. Cool. Looks clean. Control X, Y. enter to save. Let’s play “Elden Ring”. Okay, eldenring.sh can I win the first beast battle? Okay. One, dang it. But notice how it exited the program. I couldn’t battle Margaret. So let’s try it again. One. Beast vanquished, took it out. Now it’s time for Margit. Can I do this? Seven? If I do this, I’m going to freak out. Okay, I died. And that’s “Elden Ring”. Now, if you can do that, you got crazy lucky. I don’t know how you did that. Now with games like “Elden Ring”, they become more fun when you find out like some secret codes, some hacks, some cheats to help you win better because they’re really hard. So we’re actually gonna bake that into our game. But gimme one sec. I want to talk a little bit more. Let’s go back into our script here. Let’s talk more about this if statement. So far, we’ve done something very simple. I mean, it’s all simple, it’s just going to be different. So far we’ve said this. If this piece of data equals this piece of data, then do something. But we can do more than just equals. Like let’s actually get outta the script. Sorry I made you get in there uselessly. Let’s get out. Let’s write a new script just to make things cleaner. Nano test.sh just for fun. Shabang! Did I scare you that time? Man, I’m gonna get you one day. And let’s do something simple. Let’s do if, opening brackets and we’re gonna change our symbol up. We’re not gonna do equals let’s say if two is greater than one, closing brackets, semicolon, then do something. Echo this is true. And we actually don’t need the else that’s all we have to do. We just have to put in a fi. So X, Y, enter to save. I’ll make that executable real quick. Chmod plus X test.sh and then we’ll just run that sucker test.sh. Yeah. So it just echo it out. This is true because two is greater than one. So we can use greater symbols. We can also do greater than or equal to, less than less than or equal to. And coming back to our “Eldon Ring” script, we can evaluate more than just one expression. Is that how you say it? Yeah. So let’s get back to our “Elden Ring” script. Nano eldenring.sh Here in our boss battle, we’re gonna add a cheat code. So in this if statement here, we’re still gonna say, yeah, if your attack equals the attack of the beast, you win, but then I’m gonna do this. Right here in these brackets, in the if statement. The statement that’s gonna be a value true or false. I’m gonna hit a space after tarnished and then do double pipes, just like that. If you’re like, man, I can’t find that on my keyboard. It’s the backslash, just underneath the backspace, you had to hold down shift. Don’t worry. We all had to learn it. Anyways, some I’m gonna do two pipes and then another thing to evaluate. And I’ll say variable tarnished equals the string coffee. What’s happening here? What’s happening is powerful and fun. With these two pipes, I’m actually saying, hey, if beast equals tarnished, cool, it’s true. Or, and that’s what these two pipes mean. It means or. So this needs to be true or this needs to be true. So if either of those are true, then do this. And you may have picked up that we just added our cheat code. Our cheat code is coffee. So I could pick zero through nine and maybe get lucky or I could research the cheat code and say, you know what? If I just type in coffee, dude, I’m gonna win. Let’s try it out. So let’s save this code, this script. Control X, Y enter to save. Let’s run our script. Let’s play “Elden Ring” ./eldenring I still have the battle of the first boss. I forgot to do the cheat code for that. Okay, here we go. Zero, died. Let’s try it again. Zero, beast vanquished. Got it. Okay, here we go. Zero through nine. Not today’s sucker. Let’s type in coffee. I beat Margaret, Margit. I beat him. Did it. With cheat code, still feels good. Now lemme show you one more thing with this. Let’s get back into our script. Here in our boss battle, we said this statement will evaluate to true if either of these conditions are true. So this one or this one. Now in addition to, or we can also do and. So let’s try that real quick. Actually. I’m gonna make the first beast battle a bit harder because it was too easy, let’s be honest. So here I can say within the brackets, instead of pipes, I’ll do ampersand, ampersand. And I’ll say, I don’t know, 47 is greater than 23. So what we’re saying here is that in order for Mr. Bash script to evaluate this entire expression as true, both this one and this one have to be true. It’s not an or situation anymore. It has to be both. Now, thankfully 47 is greater than 23. We win. Awesome. As long as we get the right number here, let’s try it out. Let’s try it out. Let’s play “Elden Ring”. Okay, here we go. Zero. I died. Okay. Zero. Got it. So at that point, my attack matched the beast attack. Zero, zero and 40, was it 42 is greater than 27? It always is. So two things evaluated. I’ll just beat Margit again. Coffee took him out. Coffee always wins. Now here, I’m gonna show you a couple ways you can take your game and make it even crazier. I’m sorry, but watch this. It’s a little thing called nested ifs or nested conditionals. Let’s get back into our “Elden Ring” script. Nano eldenring.sh and let’s go to our boss battle. What do you say we make the boss battle harder? Let’s do that. So first we’re gonna take out this echo right here, where beast is vanquished. We haven’t vanquished him yet. We can’t do that yet. It’s too easy. Let’s take it out. Here, we’re gonna do another if statement. This is crazy. If something else is true after the thing before it was already true, what? Watch. Let’s say only the root user can actually win this battle. So we’ll say if variable user is equal to root colon, then we can echo beast vanquished and then we’ll need to close out this nested if. So what what’s happening here? I know this is really strange. We put an if statement another conditional inside an if statement. So now what we’re saying is not only does this first if statement have to evaluate to true, but once that evaluates, we got another hurdle to jump through, another thing to do, a second if statement and that one has to be true too to vanquish the beast. Let’s try it out real quick. Okay, control X, Y, enter to save. Let’s run our script “Elden Ring”. Okay, I gotta battle this first beast. Zero. Got it. Okay, next one. Coffee always wins beast vanquished. So what happened there is first of all, coffee, it wins. Second, I am root. If I do echo user, I am root. So that’s who I am. But what if I were someone else? Now, you don’t have to do this, but I’m just gonna try with a different user real quick. So I’m gonna add a user Bernard. I’m gonna make a copy of our “Elden Ring” script inside Bernard’s home directory, and then I’m gonna become Bernard. SU Bernard. Cool. I’m Bernard now. I’m gonna jump into my home directory. And if I run that script, let’s see if Bernard can defeat the first battle. Got it. Bernard’s a champ. Bernard knows the secret code, coffee. This should not happen, ’cause Bernard’s not root. This should not win. Yeah, nothing happens. We just died. Didn’t even tell us. So let’s get back to being root. Woo, back to me. Okay, let’s edit our script once more. And we can see here, yeah, we passed the first one, but the second one we failed. We weren’t root. So that’s a nested if just more, and more, and more. There’s one more we can do though that’s kind of cool. It’s called in an elif, it’s else if. Check it out. So let’s take out a little extra if here. Let’s say if you do have the secret code coffee, beast vanquished. So that’s in place. So this is kind of back to our original thing, but instead of doing the else right away, we can change the else to elif. And here with elif we’ll do another statement. Let’s just do the same one we did before. If user, and this time we’ll say if user equals Bernard, that’s our evaluation. Then we’ll do something. Okay, Bernard always wins. You vanquished the beast. And at the end here, we’ll do our else, you died. No. What is happening here? With elif we’re not saying that both the first if statement and the elif statement has to be true. No, we’re not saying that. What we’re saying is, hey, if this if statement does not evaluate true, if it does go false, false you lose. Well, here’s another chance. Else, if try this one and then do something with that information, with that branch of reality. So what’s the difference between a nested if and elif? Well, a nested if, both the nested if and the parent if had to be true in order for the next thing to happen under the nested if. But for elif it’s like, hey, if you didn’t get that if statement right, come over here, do something with me. Let’s see if you got this right. Let’s try it out real quick. Oh, and I almost forgot. There’s elif statement needs his colon and then, but no fi. Fi is just for the if. Let’s control, X, Y, enter to save. Yes, save it. Copy it over to Bernard’s directory become Bernard, we go to his home directory, and run the script. Can Bernard beat the boss on the first chance? Got him. Bernard’s lucky, man. Alright, here we go. He’s gonna fail this battle. Let’s do eight, but then he always wins. He jumped right into the next elif and because he’s Bernard, it worked. Now let’s test it if I were root. So let’s exit. Okay, beast vanquished on the first try. I’m gonna try and lose the first battle here. Instead of doing coffee, I’m just gonna do one. I should lose. I actually got lucky and won! Are you freaking kidding me? Let’s try it again. Okay, I beat the first boss. Am I like crazy lucky? Let’s do one again. Okay, I died. But anyway, that’s cool, right? So Bernard just won ’cause he’s a boss. I lost ’cause I’m not Bernard. Anyways, let’s get back to the script. Now here you have more than enough to make a killer “Elden Ring” game. I gave you the building blocks. Now you gotta go crazy and go for it. But hold on, I got one more thing to show you. You see at the beginning of “Elden Ring” they give you a chance to pick your player type, you could be a prisoner, you could be a prophet, you could be a samurai. And I wanna throw that into our game. Each class has its own stats and how you can fight your way through the lands and win the game. Let’s add that in here real quick. And seriously, it should be quick. Back in our script here. This happens at the beginning of the game before your first boss fight. So we’re gonna go to the very, very top of the script. Here we go. It will even be before you first died. I wanna type in echo. I’m gonna say welcome tarnished, again that’s the name of this game or the name of you in this game. Please select your starting class. Then I’ll do like one for samurai, two for prisoner, tree for profit. Cool, that should do it. And then we’ll ask the user what they wanna be. So it’ll read class. So they’ll enter one, two or three. It’ll be stored in that variable class. And now what I wanna do with this, and this is super nerdy, I apologize to you, those of you who don’t care about these kind of games. I do. So the samurai, the prophet, and the prisoner all have different stats you start with. Their HP, or their health might start with a different number. Their attack, or their strength might start a different number. They’re magic. You see? It’s an nerdy game, might be a different number. So we need to assign the class and assign their parameters. Now we could do it like this. We could use if statements and even elif statements to make this possible. So we could do if class equals one, semicolon then type equals samurai, HP equals 10, attack magic 12. I mean, you’re getting the picture. We can assign different stats to them based on what they choose. And we can do an elif for each of these. That’s one way to do it. So it might look like this. But there’s a way better way to do this and this is something that even Python can’t do. And Python’s my favorite. This is something called case, ah, check this out. It is so cool. Case is like an if statement, but it’s more like a switcher and it’s very simple. Case, let’s type that in, case, then we’ll do a variable, class. So this is the class we’re evaluating. So case is looking at this variable and going, okay, what’s it gonna be? Then we say in, and we start our party. So hit enter, do some space, whatever you wanna do, space is not important. It’s just for us to make it pretty. Let’s do our first variable, one. So if they enter one, that’s the variable, that’s what it’s gonna equal. We’ll do a closing parenthesis, enter, and then we’ll do some space once more and make it pretty and we’ll assign our stuff. So we’ll say type equals Samurai Like you got the idea. I’ll have this data actually, the real data, below. So check it out. But I’ll go ahead and enter this and just speed forward, Nick, for me please. And then here, this is important. Now there’s so many random little rules and things you have to remember with like if statements, and nested ifs, and elifs, and now case. So just kind of like practice it so you can submit it into your brain. But at the end of one of the case options you’ll wanna do double semicolons. That tells the case here that we’re done with commands for that variable, let’s move on. So in case class equals one, do all this stuff. And now we can do another one. In case class equals two, we can do this. So Nick, go ahead and fast forward. I’ll do the rest real quick. And finally here at the end, making sure I have my double semicolon after the last option here. Just like if we’re gonna do our fi, but the version of that will be esac, just case in reverse. Esac. Telling Bash scripting, hey, we’re done with our case here. Now, this is cool ’cause it’s like a little switcher. I love that so much. And it’s so powerful. And I’ll say at the very end, we print out what we selected. So echo you have chosen the, we’ll do the variable type, class your HP is HP variable and your attack is, and we’ll do the variable attack. So that should change based on what we select in our switcher. Let me close out that. Do control X, Y, enter to save and let’s run our script. Let’s play “Elden Ring” once more. Welcome to tarnished. Please select your starting class. I’ll be a samurai. So look at that. You chose the samurai. You, that’s not correct English, I’m sorry. You chosen the samurai class. Your HP is 10 and your attack is 20. Let me just cancel that real quick and try it again. Let’s try it with the prisoner. I’ll be a prisoner this time and it totally changed. You chosen the prisoner in class. Your HP is 20. Your attack is four. That’s powerful and that opens up a whole new world, a whole new realm of making this a game. So I challenge you to make a really slick, sick “Elden Ring” game where you die a ton, make your family and friends play it, make your coworkers play it and see if they can win. Anyways, I wanna see if I win this one. Zero. I died. I give up. So fellow tarnished, we built “Elden Ring” in Bash scripts, a Bash script. And along the way we learned one of the most powerful things in programming, giving our scripts the power to make their own decisions, to change based on our behavior, or behavior in the script, conditionals, if statements. We did if statements, we did nested ifs, elifs, bit of math, some crazy stuff, and even a case statement. We did some case things. Whatever the case, it was fun and awesome. Now take yourself a little coffee break. This was a lot. And now with anything in technology, pretty much anything in life to cement this into your brain, you need to practice it. You need to do it again, and again, and again until it becomes familiar to you, second nature. Now I do have some practice labs and quizzes at Network Chuck Academies, check it out, link below. That stuff will help you start to remember this and become a Bash master, a Bash pro, just really good at Bash. And by the way, these concepts apply to a lot of programming. So like, if you look at my Python series, this will look very familiar. Sure. Stranger, kinda like Mars, but it is very familiar, the concepts. And also have you hacked the YouTube algorithm today? Let’s make sure you do. Hit that like button, notification bell, comment, subscribe, you gotta hack YouTube today, ethically of course. Yeah, that’s all I got. I’ll catch you guys next time.

Check Out Network Chuck's Coffee and MERCH Shop