Hello and welcome to Command Line.
This way, we're drilling links,
shell scripting and how we can use
it to our advantage at the command
line. I'm Christopher Haler and
let's.
So we're learning objectives for
this video. We're going to
understand the purpose of a Shell
script, learn how to write a
script, and we're going to execute
a Shell script.
Pretty assessment.
What is the well known file
extension for a Linux
Shell script?
Is it a Dutch Shell
B as H, C
dot script or D.
S H script?
The answer is B.
S H.
This is the well known file
extension for a Linux
Shell script.
That s h a Dutch
Shell. That script, Dutch
Shell script. I mean, you can make
them all you want because limits on
its own kind of ignores file
extensions.
But as far as for the community
and for systems, this is a
well-known extension to help
keep track of these files.
So the purpose of Shell scripts is
that they are used to automate
process and this is very
similar to the four in the loop.
So we learned in a previous video
where you will execute
specific processes for us
without us having to do them over
and over.
And as we learned in the pre
assessment, they usually have the
same extension for a script
extension.
And it's really useful to help
provide all of this different
functionality that we've already
written in four commands to run
that way, we don't have to type them
out individually or keep typing them
over and over again.
So it's a very useful way to keep
track of these commands and
to be able to execute them quickly.
So when we write a script,
we need to start with a Shabangu
at the start, and that is that
hash tag exclamation point.
Now, what this does for a
Shell script is it tells
the Linux system which
specific Shell interpreter it
needs to use in order to run this
command.
So if we use the Shabangu
with bash,
that is just using the bass shell
for Linux.
And if you're not very familiar
with the different types of shells
from Linux, I'd recommend looking
them so you can become exposed to
these differentials and find one
that works best for you.
But as far as staying at the Shell
bash is very good and
it tells you this interpreter,
I need you to use this specific
interprete.
And so if we were running a Python
script, we could use a Shabangu and
say, hey, you need to access
the Python libraries and they
will automatically interpret
the script with Python
instead of with the VASH.
And if you're not familiar with
programing already, we use just a
single hash tag
that's used for comments to help
comment out different parts of code
and it will not be executed.
So writing a Shell script, we're
going to use very similar
functions as the the
one line for an while loop that we
learned previously where we
have a shabangu at the top
and then we have the same for
I, where we're defining that
parameter in this list of numbers
I want you to echo.
And it's important to
keep in mind that we have this
different type of tabbing for the
shell and it's a lot
easier to read into troubleshoot if
we need to do that and we have the
done as well.
So let's go ahead and give an
example of this script.
So if I'm going to do less
bash L.A.
and I have my echo loop that show.
So let's go NENO
Echo Loop, Dutch Shell to see what
it looks like.
And I have my Shiban here
have are for loop and
the Done So exit
and we're going to run it just like
any other program where we use the
dot forward slash,
let me spell it correctly, echo loop
that as H and run
and that goes ahead and spits out
exactly what we told it to.
One through ten echoed.
So this is a very useful way to be
able to write and
execute the script.
And so as we learn, we
need to do the forward slash
and then the name of the file in
order to execute it.
And just like any other
executable file, we may need to
change the file permissions
with the of command that we learned
from a previous video
and make sure you have that
execute permissions set so
you may need to do chmod plus
X and then the name of the file in
order to execute it.
So this is very useful
and you need to keep this in mind
when you're writing your scripts.
And if you don't have permission to
run them, that's most likely because
you don't have that execute
permissions set.
All right, supposed to sustain you
write a script, but you don't have
the permissions to run it, what
command do you execute?
Is it A, a.
B, then C,
I have config or D,
D, D, but we are changing
the file mode in order to
have that execute permission to run
our code.
The NATO command is very useful to
write the code, similar with the VM
where we can write our Shell script,
but they are not used to execute
the program or configure
their permissions to execute it
in the config.
Command is used for networking,
for interface networking, and it's
not used to help execute
any scripts.
All right, so in this video, we
understood the purpose of Shell
script, we learned how to write a
Shell script, and we also learned
how to execute a Shell script that
we wrote. And I hope to see you in
the next video.