BASH scripting will change your life
![*](https://i0.wp.com/allprowebdesigns.com/wp-content/uploads/2023/12/1703049287_maxresdefault.jpg?resize=840%2C430&ssl=1)
Video Title: BASH scripting will change your life
We already know that bash is powerful and it will make you an awesome it engineer, but it can also change your life. Well, kind of it can actually make each day of your life better. So in this video, allow me to introduce the bash Butler,
A script designed to make you feel awesome and informed every day. In fact, here’s a sneak peek. Whoa, whoa, hold on, buddy. You gotta watch the video first because there are things in there that might be new to you. Like variables and arguments,
Really fun stuff that you’re gonna learn in this video. So my bash friends, my bash club, my bash brothers and sisters, that’s probably better hit your coffee. Ready? Let’s dive deeper into bash. The first thing we’re gonna do is actually start writing a script with the
Knowledge we gained in the first episode and see if you can do this by yourself. Here’s the criteria, name, your script best day ever.sh. And I want your script to greet you with these three messages and feel free to replace Chuck with your name and bonus.
Give one set of waiting time between these two messages and finally make your script executable. Pause the video. Go UN pause. Let’s walk through it real quick. And by the way, if you have no idea how to do this, that’s fine. Just go back and watch episode one.
I show you how to do this and you’ll need that knowledge in order for us to continue building this crazy awesome script. Just trust me. Here we go. Now first I’ll spin up my Linux lab by going to in the o.com/network. Chuck here in ode, I’ll actually create a virtual machine,
A Linux virtual machine in the cloud, and it will only cost me one penny per hour, which is insane. And if you’re neutral ode, you get a hundred dollars free credit for 60 days just for signing up. And as you can probably see, ode is my cloud provider of choice.
I have like a million virtual machines in the cloud. It’s how I run my business. And it’s my favorite play used to practice Lennox because I can quickly spin up a Lenox lab in the cloud. It boots up in seconds and when I’m done,
I’ll delete it. So it literally only costs me one penny. So if you wanna learn Lennox the best way you gotta get hands on. So go and get logged in below. We know.com/network, Chuck, and look, mine’s already up and running.
So I’m gonna grab my SSH access over here just by copying this one little command and I’ll launch my command prompts in windows or terminal and Mac and Lennox, pace. My command hit enter, accept all fingerprints, put in my password and I’m it. And by the way,
If you already have your own Linnux machine, that works too. So here we go. Time to write a script, quick coffee break. Don’t worry. It’ll be plenty of these. And I will go a bit fast. If you are confused, go back to epic. Oh one, here we go. First,
Let’s create a script named best day ever.sh let’s do it nano best day ever. DOH done. I’m already editing a script. And how do we start each script Shang? Sorry. Didn’t mean to scare you shebang in place, Rockton task. Number two, let’s knock it out.
I’m gonna use the echo command to talk to myself or have my script. Talk to me and I’ll use a sleep command to make it sleep in between commands Looks good, task two, done task. Number three, let’s make the sucker executable control X Y enter to save.
And then I’ll do C H mod plus X and the name of my script. Bam. We did it. If you did that by yourself. That’s awesome. And what do you say? We actually run our script, Man. I already feel so great. Best way to start the day. Don’t you feel awesome,
But there’s more. We can do more, but hold on. Before we do that, this has awesome and really great for us. You Chuck, whoever you are, but what if our friend Patricia, what if she also wants to start her day?
Awesome. And honestly, she needs this cuz she can’t even get into a coffee shop. So let me ask you, what do we have to do to make sure that this says Patricia so that she has a great day? Well, you might think let’s just go edit the script and we could do that.
We’ll type in nano once more, the name of our script, best day ever dots sh and edit that sucker. And we could painstakingly go through and change each of these names, but we can’t do that. We’re it people and we are lazy.
So I wish there was a way we could just change all the names at once. There is. So that’s why we’re doing this right there is it’s really cool. Check this up new concept time. We’re going to create something called a variable.
Go ahead for me and type in name. That’s it. And then do the equal sign. And then in quotations type in let’s just say Patricia and then close with quotes. There we go. This right here, this name, that sucker is a variable.
And when you think of variable, I want you to think, Hey, it can change. And here’s what we’re gonna do with it. Ho ho instead of manually typing in Chuck or Patricia or Ben evil Ben, instead of doing that, we’ll go in here and I’ll use my Curia.
Go ahead and do this with me right now. I’m gonna take away Chuck and I’m gonna type in dollar sign name, and I’ll do it on every one of these lines here, remove all the chucks. Now we’ll walk through this, but I wanna just execute it real quick.
Let’s do it together. So we’ll go ahead and exit and save our file. Control X Y enter and let’s to run our script period four slash best day ever. And check this out. How cool is that? It replaced the name that we put in there with a dollar sign with Patricia,
Let’s jump back in the script nano best day ever.sh by simply typing in the word name and saying, Hey, I want this to equal something. And this example is just gonna be text that says, Patricia, we created a variable. And then we use that variable by using a dollar sign.
And then the name of that variable, which it’s also name, which is kind of confusing. It’s okay. We we’ll get past it. So again, here we created the variable and here we used it. Let’s try it again real quick. Instead of Patricia, let’s change the variable name to Ben.
Go ahead and do that for me real quick. Pause. I’m pause coffee break. Now let’s do it. I’ll change Patricia to evil. Ben control X Y enter let’s run the script one more time, best day ever for evil. Ben, how cool is that?
We only had to change one thing in our script and it changed everything else. That’s a power of variables and not only do they save us some time, that’s awesome. They are also cool, crazy powerful. And you’re about to see that.
Now let’s jump back in our script nano best day ever do sh what we did here was cool. We manually set a variable name equals Eagle bin or Patricia, whoever it is, but that’s not the only way we can set variables.
And that’s a good thing because at this point we still have to manually change something. And again, we’re lazy. We have to automate this. That’s what bass scripting’s all about. So what I wanna do is change it to where whoever comes in and uses my best day
Ever script. It’ll just match to them. For example, if my wife Abby comes in, I wanted to just say Abby or my daughter, Chloe, or my brother Cameron, or my video editor, Nick. I want this script to make their best day ever happen.
And I don’t want to have to do anything. How do we accomplish that two ways? Check this out first way. Go ahead and delete this right here. Take it out. Goodbye. Goodbye, April Ben. And this might feel a little weird,
But go ahead and type this in read space name. Okay. What does that mean? I’ll tell you in a second before that, let’s go ahead and do an echo and say, what is your name? You probably see where this is going, but let’s, I’m not gonna spoil it for you.
Let’s take control X Y enter to save and get outta there and let’s run our script best day ever at sh run it. What is your name? Okay. Maybe we should answer. Let’s say Nick, What, how cool is that? We just got even lazier mission accomplished.
Let’s get back into our script nano best day ever. Sh what just stinking happened instead of setting the variable name manually just saying name equals Patricia name equals Ben. We’re saying, Hey, why don’t we ask them what the variable should be? Let’s ask the user,
The one using the script. And that’s what the read over here is doing. Read will get some user input and that input will be stored inside the name variable or the variable name. That’s amazing, right? That’s so fun. Think of all the things you could do with this. In fact,
You should play around with this. Just have fun. Go crazy. Have your, your wife, your husband, your brother, your sister, your friend, your coworker, run the script and do something. I set a lot of names there. I’ve had a little bit of coffee this morning.
Now there is one more way to do this, and it’s really fun. Check us out. So go ahead and take out Rena. In fact, take echo. What is your name? Take out all that. And we’re gonna do this. And this is gonna feel weird too.
Really weird type in name like we did before. Like when we we’re setting the variable manually type in equals, but this time do this with me. Dollar sign one. What, what is that? I’m not gonna tell you. We’re gonna run the script control X Y enter to save.
I’m gonna do control. Will L to clear my screen, make it nice and clean, and we’re gonna run the script again, but hang with me real quick. Go and type in period slash best day ever. Sh but before we run it right after that, go ahead and put in a name.
I’ll see my wife, Abby. So Abby and go, what what’s happening? How did that get there? Right there? We just got into an, an argument, a really fun argument. That’s what these are call by the way. Let’s get back into our script, nano best ever. Ah, I’ve been saying that too many times.
We just got into an argument with our script and we actually won and had fun specifically. This is called a positional argument or a positional parameter. And whenever we ran our script, you know, period, four slash best a ever SSH, whatever parameter we put right here after the script, we’ll match up $2,
Sign one keeping in mind that it’s the first parameter we’re putting. So it matches up to one first one, first one. Got it. Yes. Okay. And that means we can do this, check it out. We can have more parameters. For example, my wife, Abby probably doesn’t wanna be complimented on her beard.
Just a wild guess. Probably won’t make her best day ever. So we gotta change that. So real quick, actually challenge knowing what we’ve done here, use a positional parameter and argument to make that change and make you unique to everyone who comes in. Pause a video UN pause, coffee. Purple.
So first I’m gonna set a new variable. Now I’m gonna use a positional parameter. It’s kind of fun. Say positional parameter. I wanna name mine compliments and I’ll have that equal dollar sign two. And then down here under beard, I’ll just put in the variable dollar sign complement. Bam. That should do it.
Control X Y enter to save. Let’s try it out. So let’s run our script period. Four slash best day ever dot H I’ll say Abby as the name. And then my second parameter will go right after that. And I’ll say eyes,
Let’s try it out. This is so cool. Right? Bam. Good morning, Abby, look at that. We see your first parameter in action. Abby, Abby, Abby, and then our second one comes in right here. Eyes instead of beard. That’s just fun. That’s just so cool. But the fun isn’t over yet,
Our bash Butler best day ever, a script isn’t done, he can be and do so much more. So using the skills we’ve learned so far, let’s take it to the next level. Let’s go. Let’s jump back into our script. Nano best day ever.sh so far,
We’ve set variables equal to simple things like text or strings. That’s what we call text in the scripting world. But this is crazy powerful. You can also have variables equal the of commands. What does that mean? Let me show you. So actually let’s get out of our script.
Sorry I made you do this. Needlessly hit control X. Let’s learn a few quick commands real quick to figure out who you’re logged in as like, who am I type in one word who am I? That’s the command. So fun.
You are root. You’re logged in as root. If you set up Le node, you might be somebody else. That is your username. Another fun one is to figure out, Hey, where am I in the file system? Am I in my home directory? Am I on the desktop? Am I in downloads?
We can figure that out real quick with the P WD command print, working directory, bam. Hey, we’re in the root directory. Cool. And one more fun one if you’re like, Hey, what day is it today? Just type in date. The command is date bam and tells you.
So now what we’re gonna do is take the output of these commands and put them inside a variable that we can use in our script. Let’s try it out. Okay. Let’s go. Let’s jump back into our script nano best day ever about sh first thing we’ll do
Is set our variables. So up here, just under compliment, we’ll create a variable called user and we’ll have that equal. The who am I command? And it’s a bit different than how we’ve done it before. We’ll use the dollar sign here. I know this is kind of new. We’ll do pro parenthesis,
Open parenthesis and the command who am I? And then close that parenthesis. This is the format we’ll use. We want to make sure a variable will equal the output of command. So go ahead and do that for the date command and the PWD command.
Do it right now. Pause the video On pause, coffee break, and let’s do it. I’ll create able date and have that equal the command date. Easy enough. Now I’ll create the variable. Where am I? And have it equal to the command.
P w D cool. Now time to use our variables in our script, and you can do this yourself. It could be whatever you wanted to do. Just something fun. I wanna say down here, sleep two, sleep for two seconds. And I’ll echo, you are currently logged in as,
And we’ll use our first variable dollar sign user. And you are in the directory dollar sign. I’ll say, where am I? They’ll say? Yeah. Also today is, and then I’ll use my variable date. They’ll use a quote at the end here to close that up.
And right now that’s a pretty heavy sentence, right? Like we’re echoing a lot of things using our user variable. Our, where am I variable and our date variable. What do you say? We try it out. Let’s do it. Control X Y enter to save. I’m gonna do control L pre screen,
And then we’ll run our variable keeping in mind. We have to use our positional parameters too. Read slash best day ever. I’ll say Bob and ice cream. Let’s try it out. Ready, set, go. And then yes, the commands. We are harnessing the power of the commands and using them in our script and
Variables. We’re currently logged in as the root user. We’re in the root directory and is this at a certain time? Whatever. So not only is our script just encouraging the heck out of us, making us have a great day from the get go. It’s also informing us about things.
Speaking of which we can do more. Like we can go down a rabbit hole and get a little crazy. Do you ever do that? That’s what I do then that’s what we’re gonna do for the rest of this video.
We’re gonna go down a little crazy rabbit hole and make this a little extra. Is that okay? Let’s do it. You know, actually we’re gonna stop there because the video’s already too long, about 14 minutes, but don’t worry. I still do go down that crazy rabbit hole.
In fact, this is the end result of the script. It’s kind of crazy when you run the script. In addition to what we already covered, it’s gonna tell you your private IP address, your public IP, address, the weather of a city of your choosing and the dad joke of the day.
That’s how you have a great day. If you wanna check it out, I do have a link alone, the description to network Chuck academy, that video will live there anyways, back to Chuck in the past to close out this video, back to you, Chuck, and also have you hacked the YouTube algorithm today.
Let’s make sure you do hit that light, but notification bell COMT subscribe the, say it all. Yes. You gotta hack YouTube today. Ethically. Of course. Yeah. That’s all I have. I’ll get you guys next time.
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
For a very easy but also very useful bash script exercise for beginners, you can try automating "sudo apt update && sudo apt upgrade" by making it a clickable icon on the desktop. Uses many of these same skills, very low difficulty, and you end up with something that saves you time every time you update and upgrade!
the chmod thing never works for me nothing does
but does Patricia have a beard?!?!! 😂
#!/bin/bash
#!/system/bin/exec
Super bash bros
man i from india , i like ur teaching so much , i was feeling like i taking live classess from u and i enjoyed this more than mr beast videos
Sir i have an doubt about linux.
if i install an application on linux based system. can i run that on terminal or can I run these application Like Vue framework style. I have question but, I don't know how to ask this
have to pause for a moment for praising the amazing guy and teacher i've ever met!!!
Brand new to hacking (white hat) and programming and your videos are the best and most helpful thank you NetworkChuck!
The passion & enthusiasm … Blessings Chuck!
hey i think instead of using linode u can use wsl ububtu and sudo su root
it is like roblox lua
Very nice 😊😅❤
Very interseting dude, that's awesome. I like it more tha I expected before watching this video
If u did dat by urself…..ur awesome…..lmao, 😅😅😅. 2nd funniest ding I heard all day!!!
I love your content
Patricia has an awesome beard?……ok…..LOL
Chuck, I think you are Bash guy. Born Again Shell in Jesus. Thank you for your videos. They are hilarious
Man, your real job is to advertise because what you are advertising will resonate with everyone
Too bad Linode is not accepting me as a customer… And they are not very helpful about it
It's so beautiful 🥹
Herr Chuck is awesome!!! I can't believeam actually enjoying this bash scripts….more power to you 👏
Ummm im allergic to coffee
Other people: "NOOO dont log in as root"
Chuck: proceeds to wirte and execute bash script as root
13:25 I watched all episodes, but cand find how to find the informations. Ore is that comming in tze future?
Chuuuuuuuuuck! (*Coffee break….) What tools do you use when recording your videos? I would like to make content for the Spanish-speaking community, I have many friends who have difficulties with documentation in English (myself included).
(*another coffee break….)
I love your videos, you make being an IT engineer more fun.
$(echo "Greetings")
Speed to fast for a beginners and Unix screen not presentable(font to small and color ineffective)
Abbey has beard 😂
I use Wsl for most of my linux and bash stuff since i have my familiar Windows interface, but i get to use bash and kali apps.
Calming voice, nice explanations. I watched this even though I already know about this. Just because it was so relaxing to follow your tutorial. 🙂
Even though I don't speak English, this guy explains well and in a fun way
How the heck you type so fast?!🤯
I had a bash learning Bourne Again SHell .
so neat, i have a lot to catch up on.