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? Let's get started.
Welcome to episode one of my bash scripting series,
where I'm 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,
you're 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 it's a better version than the one created in 1970,
this was made in 1989 fun fact, the same year I was made,
but basically it's just this, the command line in Linux.
It's 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 couldn't handle it. So the bash shell is just how we make Linux.
Do things, make new files, add new users hack.
And if you've 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 there's more to bash.
It's 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.
Let's write our first batch script right now,
and you're only going to need two things for this first Lennox.
You gotta have Lennox. We'll take care of that here in a second.
Also you'll need some coffee. That's just the rules.
So first let's 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 we'll navigate out to
linode.com/network. Chuck. Now what's cool is if you're new to Len node,
you get a $100 credit for 60 days for free. If you're not new,
it'll 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,
it's gonna cost you what 3 cents. That's why this is my favorite place.
Just to quickly play with Lennox. Now, of course,
if you already have Lennox installed somewhere or you're rocking WSL two on your
windows computer, you can use that. That's fine,
but I'm gonna use Le node for MyLab.
So I'll go and create my computer real quick. Create Le node.
I'm 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 hour's stupid name, it put a password in and then click create.
And just like that, I've 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.
I'm gonna copy this command so I can connect to it via SSH and then launch my
command prompt here in windows CMD. Or if you're a Mac or Lenox,
it'll 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 I'll 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 it's a thing now, now real quick.
If at any time this feels kind of overwhelming. Don't worry about that.
That's totally okay. Take it slow. Pause the video. Rewind. If you have to,
and if you're like, Hey, I have no idea what's 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 we'll do a dollar sign and all caps.
Shell witch shell hit enter the bash shell. Of course.
Now let's talk about bash scripting. Now bash scripting is not scary.
All it is is automating what we're typing right here in the shell.
That's it so real quick, let's try something. Let's um,
let's say hi to our moms.
Let's do the one quick and easy command type in echo echo.
Hi mom. And that's it. Now head enter and look at that.
You may Linux say hi to your mom. How nice, but now let's automate that.
Let's automate saying hi to our mom to do that. We're 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 that's all it is story over.
It's like notepad and windows or is it text? Edit and Mac? Yeah, same thing.
That's not the only one, but it's the easiest one. So we're gonna use that.
So just after nano we'll name, our file, we'll name it. Hi mom.
And then dot S H for shells script and then hit enter
and boom, we're editing something in Linux. Now, first thing we gotta do,
and it's kind of fun up here at the very top, which is where you are right now.
It's where your cursor is type in hashtag. And then are you ready?
Watch out then put in an exclamation point ship.
Literally what it's 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, it's 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 we're 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,
it's really fun to say, you should try it Ang.
We're 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 we'll just type it in echo to make our Linux computer say stuff.
And then we'll put in quotation marks. Hi mom. And that's it.
I notice the cool little coloring it does when we typed an echo at term blue.
Hi mom, but dude, I'm 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,
that's it. You just finished your first bash script super hard right now.
Now we need to save the file, which that's probably the hardest part of,
of writing this, um, to get out of nano and also save it.
We're gonna hit control X on our keyboard and it's like, oh, oh, Hey, Hey,
do you wanna save that buffer? Just to just hit Y cause we do wanna save it.
That's what it's asking. Do you wanna save it hit Y and then it's like, Hey,
do you want the file name to be this? Are you sure? And we're like, yeah,
totally. We do. So hit enter.
And we're 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. There's 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.
That's it. We just ran a bash script. Now here,
all we did was automate the greeting, but you know,
your mom's gonna say stuff back and then we just,
our automation goes out the window. Let's automate a bit more.
So let's edit the file once more. We'll do nano. Hi mom.
Dot H here's our beautiful bash script. Let's add a few more things. Um,
so we'll say, hi mom, and we'll give us some to hi. We'll say sleep
Three seconds. And then we'll say,
and just to fill her words to make sure she knows we're listening,
sleep some more say, oh wow, sleep some more.
I can't believe that. That's probably good enough, right? Conversation over. So,
um, oh wait. No, we gotta say bye bye of you too. Okay, now we're good.
Control X hit Y enter and we're good. Now let's 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 can't 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 don't do that on mother's day.
Please. Actually, maybe do that. I don't know. But seriously,
all I wanted to hit home with here is that a bash script is just command line
commands. That's 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. Don't 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 let's but let's do it anyway. Hit enter.
This is how you learn permission denied. Why? Well,
because it doesn't have permission. Were you paying attention? No,
I'm just kidding. But here's 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 that's what we're 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 don't 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 let's do it again, LS.
But then here we're 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 don't let this scare you. I know it looks a little scary right now.
Like what, what, what the heck is that? That looks weird.
It's actually not too crazy. I promise. So first we'll focus on this.
The R w and then that last dash or tick. So it looks like this.
I'll 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 can't do or what you can't do is execute.
If you could, this would be an X standing for execute.
I'm gonna spell it right this time. Kind of. Yeah, I kind of did. Yeah,
there we go. It does not have execute permissions.
That's why is it hard to say execute permissions? There we go.
So let's add a quick, it's actually really simple. We'll use one command,
the ch mod command, and then we'll 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,
we're saying plus X or add the executable permission to that file.
That's all we're doing. So let's 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.
Let's try it out. I'm gonna clean it up here by typing in clear,
and then I'll just do, uh,
dot slash hi mom.sh bam. It totally runs.
So remember that you'll often hit this when you're writing scripts or dealing
with other people's scripts.
If you can't execute it like this it's because it doesn't have permission
quickly change that permission. And you're 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 it's a big deal. Don't downplay that now real quick.
I forget this is a cloud VM I'm working with and I've had an up running for
probably about an hour. So, uh, a whole penny I've I've, uh, paid for this,
but I'm done. So I'm gonna go in here until the node,
click on these little dots up here and say, delete, delete it.
And now it's gone and I'm not being charged for. So anyways,
in the coming episodes, we're gonna dive deeper into bash scripting.
And in each episode we're gonna keep building and building and building on goes
until we are bash masters or experts or dudes or something.
We'll figure out the name for 'em, but you're gonna be awesome at, oh,
real quick. Have you hacked the YouTube algorithm today?
Let's make sure you do hit that like button notification, bell comment.
Subscribe. We gotta hack YouTube today. Ethically of course. And yeah,
that's all. I got.
One more coffee break just to say goodbye and I'll catch you guys next time.