If you wanna become a hacker or a cloud engineer, or pretty much anything in it, learning bash, learning this skill will make you awesome.
It will take you to the next level, giving you the power to automate things like hacking networks, but faster creating virtual machines in the cloud, but just faster, essentially, this will make you a better nerd. And if you can learn to wield this power, it, you well powerful and super valuable to employers. So just learn it. Okay.
Just learn it. So are you ready to learn bash? Lets get started.
Welcome to episode one of my bash scripting series, where Im gonna take you from, Hey, what the junk is a bash script to knowing and understanding how to do stuff like this at a script. This is a hacking script, by the way, youre gonna learn that now first bash. What, what even is that bash stands for the born again, shell born again, because first I like to believe that Lennox loves Jesus, but also because its a better version than the one created in 1970, this was made in 1989 fun fact, the same year I was made, but basically its just this, the command line in Linux.
Its how we interact with the Lenux operating system.
And they call it the bash shell because it kind of wraps itself around the Linux kernel, shielding us from all the scary inner workings of Linnux because honestly we probably couldnt handle it. So the bash shell is just how we make Linux.
Do things, make new files, add new users hack.
And if youve seen my Linux for hacker series, we spend a lot of time talking about the bash shell, our happy place.
So learning how to use it is super powerful, but theres more to bash.
Its also this crazy powerful programming slash scripting language.
And we can write scripts that do a bajillion powerful and scary things. Again, if you can learn how to wield this power, nothing can stop you so off talking about it.
Lets write our first batch script right now, and youre only going to need two things for this first Lennox.
You gotta have Lennox. Well take care of that here in a second.
Also youll need some coffee. Thats just the rules.
So first lets get our Linux lab environment ready. Thankfully, this is crazy easy things to our sponsor.
Lin node Linode is a cloud service provider, a place where we can magically deploy Linux, computers and sky in just seconds.
So go ahead and fire up your web browser and well navigate out to linode.com/network. Chuck. Now whats cool is if youre new to Len node, you get a $100 credit for 60 days for free. If youre not new, itll literally cost you about one penny per hour to run your Len node Linux computer. So legit.
If you wanna practice your bash scripting skills for three hours app to this, its gonna cost you what 3 cents. Thats why this is my favorite place.
Just to quickly play with Lennox. Now, of course, if you already have Lennox installed somewhere or youre rocking WSL two on your windows computer, you can use that. Thats fine, but Im gonna use Le node for MyLab.
So Ill go and create my computer real quick. Create Le node.
Im gonna choose UBU two 20, actually 21, the brand new stuff, throw the sucker in Dallas, do a shared CPU. Make it it real cheap. Again, 1 cent, an hours stupid name, it put a password in and then click create.
And just like that, Ive got a computer in the cloud I can play with right now.
Quick coffee break while at boots up. All right, coffee break over because mine is now running.
Im gonna copy this command so I can connect to it via SSH and then launch my command prompt here in windows CMD. Or if youre a Mac or Lenox, itll be terminal. But at that point, why are you accessing something in the cloud? You already have a Lenox computer.
Come on, get your head on straight anyways. So Ill paste it in, hit enter, except all fingerprints. Put my password in and boom Lennox, computer, and the cloud time to bash it up. Thing. I its a thing now, now real quick.
If at any time this feels kind of overwhelming. Dont worry about that.
Thats totally okay. Take it slow. Pause the video. Rewind. If you have to, and if youre like, Hey, I have no idea whats going on.
Go check out my Linux for hacker series right here. There I start with, Hey, what even is Linux to get you to this point where you can start doing some crazy bash scripting anyways, let now right here, we are already inside the bash shell. You made it, but how do we know? Well, we can put a command in right now to find out, go ahead and type it with me right now. The command will be witch.
Like the word witch, nothing crazy. And well do a dollar sign and all caps.
Shell witch shell hit enter the bash shell. Of course.
Now lets talk about bash scripting. Now bash scripting is not scary.
All it is is automating what were typing right here in the shell.
Thats it so real quick, lets try something. Lets um, lets say hi to our moms.
Lets do the one quick and easy command type in echo echo.
Hi mom. And thats it. Now head enter and look at that.
You may Linux say hi to your mom. How nice, but now lets automate that.
Lets automate saying hi to our mom to do that. Were going to write a script.
So with me right here, the terminal type in nano and space. Now what is nano? Nano is a text editor and thats all it is story over.
Its like notepad and windows or is it text? Edit and Mac? Yeah, same thing.
Thats not the only one, but its the easiest one. So were gonna use that.
So just after nano well name, our file, well name it. Hi mom.
And then dot S H for shells script and then hit enter and boom, were editing something in Linux. Now, first thing we gotta do, and its kind of fun up here at the very top, which is where you are right now.
Its where your cursor is type in hashtag. And then are you ready? Watch out then put in an exclamation point ship.
Literally what its called these two characters combined are called a Sheba.
And then just after that, put in slash Ben slash bash.
Now that might look familiar right back when we did witch shell, this is what it told us. It told us, Hey, its the bash shell, but now why are we putting that here? Well, for this reason, you see when you things in Lennox, scripts and Lennox, sometimes they might be bash scripts, which is what were doing right here.
Other times they might be Python scripts, another programming language, which is amazing. If you wanna learn that, check it out right here, or it could be go or any number of programming languages. So with our Ang, its really fun to say, you should try it Ang.
Were telling the bash interpreter, what scripting language we want to use for this script. So always, always do that in your scripts. Shang.
Just remember that cool with our ING in place, we can now automate saying hi to our mom.
So well just type it in echo to make our Linux computer say stuff.
And then well put in quotation marks. Hi mom. And thats it.
I notice the cool little coloring it does when we typed an echo at term blue.
Hi mom, but dude, Im color blind. I have no idea what color that is.
Please tell me the comment so I can, no, not that it will help, but anyways, thats it. You just finished your first bash script super hard right now.
Now we need to save the file, which thats probably the hardest part of, of writing this, um, to get out of nano and also save it.
Were gonna hit control X on our keyboard and its like, oh, oh, Hey, Hey, do you wanna save that buffer? Just to just hit Y cause we do wanna save it.
Thats what its asking. Do you wanna save it hit Y and then its like, Hey, do you want the file name to be this? Are you sure? And were like, yeah, totally. We do. So hit enter.
And were good now to quickly make sure that do indeed have a script there that we wrote hit L or not hit type in LS, LS, just like that. And hit enter.
There it is. Theres a hi mom script. So exciting.
So now how do we run our script? Very, very simple, actually.
So type in with me right now, type in bash space and then your script.
So hi mom dot essay. H you ready for this? Here we go.
Thats it. We just ran a bash script. Now here, all we did was automate the greeting, but you know, your moms gonna say stuff back and then we just, our automation goes out the window. Lets automate a bit more.
So lets edit the file once more. Well do nano. Hi mom.
Dot H heres our beautiful bash script. Lets add a few more things. Um, so well say, hi mom, and well give us some to hi. Well say sleep Three seconds. And then well say, and just to fill her words to make sure she knows were listening, sleep some more say, oh wow, sleep some more.
I cant believe that. Thats probably good enough, right? Conversation over. So, um, oh wait. No, we gotta say bye bye of you too. Okay, now were good.
Control X hit Y enter and were good. Now lets run the script once more, little hack, little tip here, hit the up arrow a few times to bring back your command bash. Hi mom.
Dot sh go and run that sucker. Hi mom.
Oh, wow. I cant believe you that Bye. I love you too. Bam. Just like that. We automated talking to your mom now.
She feels loved and we have more time. Just dont do that on mothers day.
Please. Actually, maybe do that. I dont know. But seriously, all I wanted to hit home with here is that a bash script is just command line commands. Thats it. But instead of you entering them one by one, we put it into a script and it runs auto magically.
And while this one is crazy simple, it is, they do get insanely fun and insanely complicated to where you can pretty much change the world. Dont hold me to that.
But it maybe you never know now real quick, a couple of things I wanna touch on with running our bash scripts, notice that when we wanted to run our script, we had to start with bash.
We typed in bash and then our script name. We can also do it like this, check it out, type it with me here, period slash and then the name of your script. Hi mom. Dot sh.
Now this will not work lets but lets do it anyway. Hit enter.
This is how you learn permission denied. Why? Well, because it doesnt have permission. Were you paying attention? No, Im just kidding. But heres what we did here. First of all, all we pretty much did was tell the bash interpreter bash, Hey, run this script.
And we had to use the period slash cuz we were like, Hey, the script is actually right here. And thats what were saying when we do that.
But when we tried to run it, permission denied what our high mom script is, is missing. Is the executable permission, the permission to run.
He just wants to run. Wow. I did not spell executable. Right? I dont know what that was. There we go.
Now we can actually see that we can see what permission it has earlier.
We typed in the LS command. So lets do it again, LS.
But then here were gonna do a space and then tick or dash L go ahead and hit, enter on that and something new here. We have our same hi mom, shell script, right there. There it is. And then over here we have its permissions.
Now dont let this scare you. I know it looks a little scary right now.
Like what, what, what the heck is that? That looks weird.
Its actually not too crazy. I promise. So first well focus on this.
The R w and then that last dash or tick. So it looks like this.
Ill bring it up here. These right here are, you are allowed to do with this file. You can read the file.
You can write to the file, but what we cant do or what you cant do is execute.
If you could, this would be an X standing for execute.
Im gonna spell it right this time. Kind of. Yeah, I kind of did. Yeah, there we go. It does not have execute permissions.
Thats why is it hard to say execute permissions? There we go.
So lets add a quick, its actually really simple. Well use one command, the ch mod command, and then well do a plus X and then the name of our file.
Hi mom. Dot sh the ch mod command allows us to change permissions for a file.
And then with this option, were saying plus X or add the executable permission to that file.
Thats all were doing. So lets go ahead and hit enter on that into, and that was it. Uh, now we do LS dash L once more LS dash L.
Now we got it. Now we have the executable or that X with our read and write.
So now we are allowed to not only read it and write it, but we can execute it.
Lets try it out. Im gonna clean it up here by typing in clear, and then Ill just do, uh, dot slash hi mom.sh bam. It totally runs.
So remember that youll often hit this when youre writing scripts or dealing with other peoples scripts.
If you cant execute it like this its because it doesnt have permission quickly change that permission. And youre good to go. Okay. Coffee break.
That was a lot. You just created a bash script. This might be your first one.
So congrats. And its a big deal. Dont downplay that now real quick.
I forget this is a cloud VM Im working with and Ive had an up running for probably about an hour. So, uh, a whole penny Ive Ive, uh, paid for this, but Im done. So Im gonna go in here until the node, click on these little dots up here and say, delete, delete it.
And now its gone and Im not being charged for. So anyways, in the coming episodes, were gonna dive deeper into bash scripting.
And in each episode were gonna keep building and building and building on goes until we are bash masters or experts or dudes or something.
Well figure out the name for em, but youre gonna be awesome at, oh, real quick. Have you hacked the YouTube algorithm today? Lets make sure you do hit that like button notification, bell comment.
Subscribe. We gotta hack YouTube today. Ethically of course. And yeah, thats all. I got.
One more coffee break just to say goodbye and Ill catch you guys next time.