WEBVTT

00:00.730 --> 00:02.169
Hello and welcome to Command Line.

00:02.780 --> 00:04.299
This way, we're drilling links,

00:04.330 --> 00:05.979
shell scripting and how we can use

00:05.980 --> 00:07.389
it to our advantage at the command

00:07.390 --> 00:08.919
line. I'm Christopher Haler and

00:08.920 --> 00:09.920
let's.

00:10.630 --> 00:11.649
So we're learning objectives for

00:11.650 --> 00:12.549
this video. We're going to

00:12.550 --> 00:13.899
understand the purpose of a Shell

00:13.900 --> 00:15.640
script, learn how to write a

00:15.910 --> 00:17.979
script, and we're going to execute

00:17.980 --> 00:18.980
a Shell script.

00:19.900 --> 00:21.129
Pretty assessment.

00:21.280 --> 00:22.603
What is the well known file

00:22.870 --> 00:24.760
extension for a Linux

00:24.880 --> 00:25.880
Shell script?

00:26.030 --> 00:27.399
Is it a Dutch Shell

00:27.850 --> 00:30.100
B as H, C

00:30.340 --> 00:31.989
dot script or D.

00:32.350 --> 00:33.359
S H script?

00:34.810 --> 00:35.950
The answer is B.

00:36.310 --> 00:37.089
S H.

00:37.090 --> 00:38.469
This is the well known file

00:38.470 --> 00:40.299
extension for a Linux

00:40.300 --> 00:41.439
Shell script.

00:41.680 --> 00:43.509
That s h a Dutch

00:43.510 --> 00:45.250
Shell. That script, Dutch

00:46.060 --> 00:48.009
Shell script. I mean, you can make

00:48.010 --> 00:49.629
them all you want because limits on

00:49.630 --> 00:51.002
its own kind of ignores file

00:51.250 --> 00:52.250
extensions.

00:52.390 --> 00:54.549
But as far as for the community

00:54.550 --> 00:55.824
and for systems, this is a

00:56.380 --> 00:58.090
well-known extension to help

00:58.420 --> 00:59.710
keep track of these files.

01:01.390 --> 01:03.039
So the purpose of Shell scripts is

01:03.040 --> 01:04.208
that they are used to automate

01:04.209 --> 01:05.385
process and this is very

01:06.040 --> 01:07.608
similar to the four in the loop.

01:07.720 --> 01:09.730
So we learned in a previous video

01:09.940 --> 01:11.709
where you will execute

01:12.010 --> 01:13.900
specific processes for us

01:14.110 --> 01:15.699
without us having to do them over

01:15.700 --> 01:16.659
and over.

01:16.660 --> 01:17.859
And as we learned in the pre

01:17.860 --> 01:19.510
assessment, they usually have the

01:19.810 --> 01:21.939
same extension for a script

01:21.940 --> 01:22.899
extension.

01:22.900 --> 01:24.609
And it's really useful to help

01:24.610 --> 01:25.989
provide all of this different

01:25.990 --> 01:27.579
functionality that we've already

01:27.580 --> 01:29.139
written in four commands to run

01:29.410 --> 01:30.759
that way, we don't have to type them

01:30.760 --> 01:32.524
out individually or keep typing them

01:32.560 --> 01:33.560
over and over again.

01:33.670 --> 01:35.287
So it's a very useful way to keep

01:35.530 --> 01:37.529
track of these commands and

01:37.530 --> 01:39.059
to be able to execute them quickly.

01:40.480 --> 01:42.459
So when we write a script,

01:42.550 --> 01:44.829
we need to start with a Shabangu

01:44.830 --> 01:46.539
at the start, and that is that

01:47.020 --> 01:48.900
hash tag exclamation point.

01:49.390 --> 01:51.209
Now, what this does for a

01:51.220 --> 01:52.809
Shell script is it tells

01:53.440 --> 01:55.809
the Linux system which

01:55.810 --> 01:57.231
specific Shell interpreter it

01:57.700 --> 01:59.317
needs to use in order to run this

01:59.680 --> 02:00.669
command.

02:00.670 --> 02:01.895
So if we use the Shabangu

02:02.650 --> 02:04.239
with bash,

02:04.480 --> 02:06.090
that is just using the bass shell

02:06.100 --> 02:07.100
for Linux.

02:07.120 --> 02:08.639
And if you're not very familiar

02:08.979 --> 02:10.089
with the different types of shells

02:10.090 --> 02:11.480
from Linux, I'd recommend looking

02:11.650 --> 02:13.179
them so you can become exposed to

02:13.180 --> 02:14.709
these differentials and find one

02:14.710 --> 02:15.710
that works best for you.

02:16.120 --> 02:18.159
But as far as staying at the Shell

02:18.160 --> 02:19.960
bash is very good and

02:20.080 --> 02:22.060
it tells you this interpreter,

02:22.450 --> 02:24.190
I need you to use this specific

02:24.490 --> 02:25.490
interprete.

02:25.810 --> 02:27.669
And so if we were running a Python

02:27.670 --> 02:29.139
script, we could use a Shabangu and

02:29.140 --> 02:30.512
say, hey, you need to access

02:31.360 --> 02:32.781
the Python libraries and they

02:33.250 --> 02:34.809
will automatically interpret

02:35.170 --> 02:36.999
the script with Python

02:37.000 --> 02:38.469
instead of with the VASH.

02:39.070 --> 02:40.119
And if you're not familiar with

02:40.120 --> 02:41.737
programing already, we use just a

02:41.800 --> 02:43.659
single hash tag

02:43.810 --> 02:45.339
that's used for comments to help

02:45.340 --> 02:46.960
comment out different parts of code

02:47.050 --> 02:48.429
and it will not be executed.

02:49.870 --> 02:51.669
So writing a Shell script, we're

02:51.670 --> 02:53.499
going to use very similar

02:53.620 --> 02:55.509
functions as the the

02:55.510 --> 02:57.129
one line for an while loop that we

02:57.130 --> 02:58.453
learned previously where we

02:59.110 --> 03:00.580
have a shabangu at the top

03:01.030 --> 03:03.369
and then we have the same for

03:03.400 --> 03:05.169
I, where we're defining that

03:05.170 --> 03:07.149
parameter in this list of numbers

03:07.430 --> 03:08.430
I want you to echo.

03:09.100 --> 03:10.419
And it's important to

03:10.960 --> 03:12.279
keep in mind that we have this

03:12.280 --> 03:14.439
different type of tabbing for the

03:14.440 --> 03:15.440
shell and it's a lot

03:16.330 --> 03:18.045
easier to read into troubleshoot if

03:18.220 --> 03:19.839
we need to do that and we have the

03:19.840 --> 03:20.840
done as well.

03:21.280 --> 03:22.659
So let's go ahead and give an

03:22.660 --> 03:24.069
example of this script.

03:25.630 --> 03:27.690
So if I'm going to do less

03:29.050 --> 03:30.070
bash L.A.

03:30.820 --> 03:32.729
and I have my echo loop that show.

03:33.370 --> 03:35.019
So let's go NENO

03:35.770 --> 03:37.449
Echo Loop, Dutch Shell to see what

03:37.450 --> 03:38.409
it looks like.

03:38.410 --> 03:39.729
And I have my Shiban here

03:40.450 --> 03:42.339
have are for loop and

03:42.340 --> 03:44.289
the Done So exit

03:44.740 --> 03:45.819
and we're going to run it just like

03:45.820 --> 03:47.229
any other program where we use the

03:47.240 --> 03:48.520
dot forward slash,

03:50.290 --> 03:52.479
let me spell it correctly, echo loop

03:52.480 --> 03:54.550
that as H and run

03:54.790 --> 03:56.319
and that goes ahead and spits out

03:56.320 --> 03:57.639
exactly what we told it to.

03:57.760 --> 03:59.099
One through ten echoed.

03:59.560 --> 04:01.226
So this is a very useful way to be

04:01.330 --> 04:02.330
able to write and

04:03.580 --> 04:05.590
execute the script.

04:07.240 --> 04:08.318
And so as we learn, we

04:09.100 --> 04:11.529
need to do the forward slash

04:11.530 --> 04:13.098
and then the name of the file in

04:13.270 --> 04:14.389
order to execute it.

04:14.590 --> 04:16.120
And just like any other

04:16.720 --> 04:18.369
executable file, we may need to

04:18.370 --> 04:20.229
change the file permissions

04:20.230 --> 04:21.945
with the of command that we learned

04:21.970 --> 04:23.619
from a previous video

04:24.220 --> 04:26.170
and make sure you have that

04:26.320 --> 04:28.179
execute permissions set so

04:28.330 --> 04:29.751
you may need to do chmod plus

04:30.190 --> 04:31.856
X and then the name of the file in

04:32.110 --> 04:33.129
order to execute it.

04:33.610 --> 04:35.610
So this is very useful

04:35.620 --> 04:36.879
and you need to keep this in mind

04:36.880 --> 04:38.497
when you're writing your scripts.

04:38.620 --> 04:40.335
And if you don't have permission to

04:40.450 --> 04:42.159
run them, that's most likely because

04:42.160 --> 04:43.239
you don't have that execute

04:43.240 --> 04:44.240
permissions set.

04:45.910 --> 04:47.349
All right, supposed to sustain you

04:47.350 --> 04:48.909
write a script, but you don't have

04:48.910 --> 04:50.379
the permissions to run it, what

04:50.410 --> 04:51.420
command do you execute?

04:51.850 --> 04:53.209
Is it A, a.

04:53.770 --> 04:55.779
B, then C,

04:55.930 --> 04:57.550
I have config or D,

05:00.040 --> 05:02.169
D, D, but we are changing

05:02.170 --> 05:03.395
the file mode in order to

05:04.060 --> 05:06.069
have that execute permission to run

05:06.070 --> 05:07.070
our code.

05:07.240 --> 05:09.189
The NATO command is very useful to

05:09.190 --> 05:10.905
write the code, similar with the VM

05:11.350 --> 05:13.449
where we can write our Shell script,

05:13.450 --> 05:15.790
but they are not used to execute

05:16.030 --> 05:17.206
the program or configure

05:18.040 --> 05:19.689
their permissions to execute it

05:20.260 --> 05:21.189
in the config.

05:21.190 --> 05:23.640
Command is used for networking,

05:23.650 --> 05:25.316
for interface networking, and it's

05:25.360 --> 05:26.536
not used to help execute

05:27.430 --> 05:28.430
any scripts.

05:30.220 --> 05:31.299
All right, so in this video, we

05:31.300 --> 05:32.619
understood the purpose of Shell

05:32.620 --> 05:34.237
script, we learned how to write a

05:34.330 --> 05:36.279
Shell script, and we also learned

05:36.280 --> 05:37.946
how to execute a Shell script that

05:38.230 --> 05:39.939
we wrote. And I hope to see you in

05:39.940 --> 05:40.540
the next video.

