WEBVTT

00:00.960 --> 00:02.370
Hello and welcome to Comment Line.

00:03.090 --> 00:04.319
This video we're going to go over

00:04.320 --> 00:06.035
piping in ampersand commands at the

00:06.120 --> 00:07.829
command line, how we can use them to

00:07.830 --> 00:09.230
our advantage to

00:09.900 --> 00:10.900
begin learning

00:11.880 --> 00:13.210
objectives. For this video, we're

00:13.220 --> 00:14.399
going to learn what piping and used

00:14.400 --> 00:16.066
for what the single and the double

00:16.410 --> 00:18.329
pipes do and understand

00:18.330 --> 00:19.829
what the single ampersand and the

00:19.830 --> 00:21.496
double ampersand operands are used

00:21.780 --> 00:23.399
for and how we can use them at the

00:23.400 --> 00:24.400
command line

00:25.290 --> 00:27.239
I preexistent, which often

00:27.240 --> 00:29.309
runs command to if command

00:29.310 --> 00:31.319
one fails, is it a

00:31.380 --> 00:33.419
command one single pipe command

00:33.420 --> 00:34.420
to be command one

00:35.610 --> 00:37.320
double pipe command to

00:37.770 --> 00:39.899
C command one single

00:39.900 --> 00:41.310
ampersand command two

00:41.940 --> 00:43.067
or D command one double

00:44.070 --> 00:45.420
ampersand command to

00:46.880 --> 00:48.007
answer is B command one

00:48.750 --> 00:50.340
double pipe command to.

00:50.520 --> 00:52.320
And as we'll learn in this

00:52.560 --> 00:54.310
video, the Double Pi will

00:54.420 --> 00:56.279
run a second command

00:56.280 --> 00:57.959
if the first command fails.

00:58.290 --> 00:59.909
This is very useful for trying to

00:59.910 --> 01:02.039
keep track of if a certain

01:02.040 --> 01:03.929
command is working properly

01:03.930 --> 01:04.889
or not.

01:04.890 --> 01:06.819
And similarly with the double

01:06.870 --> 01:08.909
ampersand, it will run command to

01:08.910 --> 01:10.739
its command. One is

01:10.740 --> 01:12.629
executed properly, not if

01:12.630 --> 01:13.630
it fails.

01:13.650 --> 01:15.269
So we'll learn more about this in

01:15.270 --> 01:16.270
this video.

01:17.250 --> 01:18.329
It's the single pipe.

01:18.410 --> 01:19.409
This is something that we've done a

01:19.410 --> 01:21.419
lot already. In this course, it'll

01:21.420 --> 01:23.037
take the standard output from the

01:23.220 --> 01:24.984
first command and it will pass it as

01:25.230 --> 01:27.329
standard input to this second

01:27.330 --> 01:28.259
in command.

01:28.260 --> 01:30.024
Very useful way to link two commands

01:30.450 --> 01:31.969
together. And it gives us a lot

01:32.340 --> 01:33.810
of really strong functionality

01:34.230 --> 01:36.269
and opportunity at the command line.

01:36.660 --> 01:38.081
And as we were using it, it's

01:38.730 --> 01:40.680
used a lot with less or more.

01:40.980 --> 01:43.099
And we can also use it with grip

01:43.110 --> 01:44.750
so that we can look through and grep

01:44.760 --> 01:46.170
for files and

01:46.740 --> 01:48.308
execute these different commands

01:48.420 --> 01:50.489
together by piping all of the output

01:50.820 --> 01:52.920
to the later commands.

01:53.250 --> 01:54.250
So very useful.

01:54.300 --> 01:55.709
You should be very comfortable with

01:55.710 --> 01:57.179
the signal because you're going to

01:57.180 --> 01:58.949
use it a lot at the command line.

01:59.100 --> 02:00.668
And it is a very, very effective

02:01.170 --> 02:03.299
way to utilize the output from

02:03.300 --> 02:05.310
commands in order to be able to

02:06.300 --> 02:08.159
run additional commands and

02:08.160 --> 02:09.270
manipulate that data.

02:10.930 --> 02:12.498
So the double pipe, this is used

02:12.910 --> 02:14.949
to execute a second command only

02:14.950 --> 02:16.370
if the first one fails.

02:16.810 --> 02:18.430
So this is really useful if you're

02:18.460 --> 02:20.259
looking for functionality or if

02:20.260 --> 02:22.270
we're using it in scripting where

02:22.840 --> 02:24.549
if we're running a script and we're

02:24.550 --> 02:25.749
going through a huge list of

02:25.750 --> 02:27.122
computer names and let's say

02:27.610 --> 02:29.374
that it cannot connect to a specific

02:29.710 --> 02:30.710
computer game.

02:30.730 --> 02:32.439
Well, if we use the double pipe, we

02:32.440 --> 02:34.479
can say, hey, if this command

02:34.480 --> 02:35.769
does not work for this computer

02:35.770 --> 02:37.436
because that computer's offline or

02:37.510 --> 02:38.960
it's not connected, shut down for

02:39.430 --> 02:41.259
whatever reason it is, then I want

02:41.260 --> 02:42.260
you to echo, hey, I

02:43.090 --> 02:44.079
can't connect.

02:44.080 --> 02:45.610
And as you can see in this first

02:45.910 --> 02:47.740
example, if we do ping,

02:47.770 --> 02:49.349
this house does not exist.

02:50.170 --> 02:52.060
It will echo, hey, I can't ping it.

02:52.930 --> 02:53.959
So let's give a quick

02:55.030 --> 02:56.050
demonstration of that.

02:57.010 --> 02:58.889
So we're going to do

02:58.900 --> 03:01.119
ping. This does not

03:01.480 --> 03:02.480
one not that

03:03.310 --> 03:04.209
exist.

03:04.210 --> 03:05.880
And this is not a real address.

03:05.890 --> 03:07.654
So there is no way is going to ping.

03:07.660 --> 03:08.860
It will do a double

03:09.670 --> 03:10.670
echo.

03:10.850 --> 03:12.789
I can't ping

03:14.750 --> 03:16.379
now since we know that this house

03:16.390 --> 03:18.105
does not exist, we can already know

03:18.280 --> 03:20.139
that this ping command is going

03:20.140 --> 03:21.079
to fail.

03:21.080 --> 03:22.469
Since we're using the double pipe,

03:22.690 --> 03:24.099
we know that it's going to execute

03:24.100 --> 03:25.100
this echo command.

03:26.200 --> 03:27.099
So check it out.

03:27.100 --> 03:28.599
So Ping request cannot not find the

03:28.600 --> 03:30.430
host. This does not exist.

03:30.940 --> 03:33.069
And since that command failed,

03:33.300 --> 03:34.479
it ran the echo command.

03:34.630 --> 03:36.639
I can't ping and

03:36.640 --> 03:38.110
now we can validate this where

03:38.500 --> 03:40.599
we can ping our lookback

03:40.600 --> 03:41.559
address.

03:41.560 --> 03:44.439
And this is one twenty seven 0.01.

03:44.770 --> 03:45.819
And if you're not familiar with the

03:45.820 --> 03:47.919
loop back, it is a non ratable

03:47.920 --> 03:49.749
only local system address.

03:49.780 --> 03:51.699
So we know that every single time

03:51.700 --> 03:53.464
is going to be able to ping this and

03:53.500 --> 03:55.119
since it can ping it, it's going to

03:55.120 --> 03:56.770
ignore this double pipe.

03:58.570 --> 03:59.949
So don't run through really quick

04:01.180 --> 04:02.620
and then we go and finish the ping

04:03.040 --> 04:04.749
and we did not get the echo.

04:04.760 --> 04:06.610
I can't ping because that

04:06.640 --> 04:08.409
first command executed properly.

04:10.260 --> 04:11.879
So we the ampersand, the single

04:11.880 --> 04:13.056
ampersand on windows, it

04:13.740 --> 04:15.259
is used to execute a additional

04:16.050 --> 04:17.550
command after the first command.

04:17.940 --> 04:19.799
This is not checked for any error

04:19.800 --> 04:21.172
or any success for the first

04:21.329 --> 04:22.554
command. And it is really

04:23.250 --> 04:25.079
useful be able to submit a bunch of

04:25.080 --> 04:26.746
different commands all on the same

04:26.910 --> 04:28.135
line. So this is a useful

04:29.220 --> 04:30.886
way to string a bunch of different

04:30.990 --> 04:32.730
commands all together, all at once.

04:33.240 --> 04:34.589
And if you're not familiar with

04:34.590 --> 04:36.600
Linux, it's similar to the

04:36.810 --> 04:38.699
semicolon on the Linux

04:38.700 --> 04:39.689
Shell.

04:39.690 --> 04:40.979
So we'll do a quick demonstration of

04:40.980 --> 04:42.930
that or I will do echo

04:43.410 --> 04:45.600
one, ampersand

04:45.750 --> 04:46.879
echo two.

04:46.920 --> 04:48.684
So it's going to do echo for one and

04:48.870 --> 04:50.899
then immediately execute Echo two.

04:51.750 --> 04:53.519
And as you can see, we have one end

04:53.520 --> 04:55.589
or two. So executed those commands

04:55.590 --> 04:56.590
directly.

04:57.280 --> 04:58.619
And it does not check for an error

04:58.620 --> 04:59.620
or success for

05:00.610 --> 05:02.470
Linux, the single ampersand

05:02.500 --> 05:03.872
is used to execute and run a

05:04.330 --> 05:05.860
process in the background.

05:06.310 --> 05:07.731
Now, when I'm using the Linux

05:08.170 --> 05:09.789
terminal, I like to use the single

05:09.790 --> 05:11.529
ampersand to start a

05:11.620 --> 05:12.620
new application from

05:13.480 --> 05:14.803
the command line and allows

05:15.730 --> 05:17.679
me to keep control of the terminal

05:17.680 --> 05:18.519
as well.

05:18.520 --> 05:19.745
So that's a really useful

05:20.470 --> 05:22.120
application of being able to use it.

05:22.630 --> 05:24.159
You can do a quick demonstration of

05:24.160 --> 05:25.989
that. So I have my Linux

05:25.990 --> 05:26.990
Mint machine up.

05:27.130 --> 05:29.019
Now let's say I want to

05:29.020 --> 05:30.639
open up Firefox,

05:31.000 --> 05:33.220
so I'm going to type in Firefox

05:33.490 --> 05:34.649
and a single ampersand

05:35.500 --> 05:37.019
and as you can see, is starting

05:37.450 --> 05:38.450
on page thirty six.

05:38.560 --> 05:39.339
Sixty two.

05:39.340 --> 05:41.300
I still have control over my

05:41.330 --> 05:43.359
terminal and Firefox

05:43.360 --> 05:44.880
is taking its time starting up.

05:45.340 --> 05:46.299
And here we go.

05:46.300 --> 05:47.649
So we've got Firefox up

05:48.250 --> 05:50.529
where if we just type Firefox

05:50.770 --> 05:52.779
without the let me spell

05:52.780 --> 05:54.819
it properly Firefox

05:54.820 --> 05:57.129
without the ampersand, then

05:57.160 --> 05:58.777
the terminal is going to hang and

05:59.230 --> 06:01.149
it will only give us access back to

06:01.150 --> 06:02.559
the terminal once

06:03.340 --> 06:04.899
Firefox is closed.

06:06.850 --> 06:08.470
So as you can see, we can type in

06:08.650 --> 06:09.760
everything, but nothing is not

06:10.180 --> 06:11.049
working.

06:11.050 --> 06:12.550
So let's close it out.

06:13.180 --> 06:14.944
And now it'll finally give us access

06:15.190 --> 06:16.190
back to the terminal.

06:19.030 --> 06:20.630
All right, with a double ampersand,

06:20.740 --> 06:22.359
so what this does is it will execute

06:22.360 --> 06:24.026
a second command only if the first

06:24.100 --> 06:25.374
command was successful, so

06:26.110 --> 06:27.759
it will only execute if there were

06:27.760 --> 06:29.589
no errors on this first command.

06:30.040 --> 06:31.809
So this is another useful way to be

06:31.810 --> 06:32.810
able to use these

06:33.640 --> 06:35.499
kind of operations in order to

06:35.500 --> 06:36.500
get what we need.

06:36.910 --> 06:38.559
So this is the opposite of the

06:38.560 --> 06:40.420
double pipe where if we ping

06:41.050 --> 06:42.819
our loop back address and say Echo

06:42.820 --> 06:44.679
good, we know every single time

06:44.680 --> 06:46.779
that is going to be a valid use.

06:47.590 --> 06:49.256
And then if we ping something that

06:49.270 --> 06:50.936
we know is not going to work, then

06:51.220 --> 06:53.109
we know that we are not going

06:53.110 --> 06:54.880
to get that echo

06:55.030 --> 06:57.010
because it only works on

06:57.280 --> 06:59.110
two on a successful

06:59.260 --> 07:00.260
command.

07:00.640 --> 07:02.740
So let's say ping

07:03.460 --> 07:05.169
two seven zero zero one

07:05.770 --> 07:07.839
double ampersand echo

07:09.130 --> 07:10.130
works.

07:11.260 --> 07:12.969
And since we know we can always ping

07:12.970 --> 07:14.636
our loop back address, it's always

07:14.980 --> 07:16.899
going to echo works

07:16.900 --> 07:17.950
that second command.

07:18.550 --> 07:19.929
Now, likewise, if we do

07:20.920 --> 07:22.540
a host that we know does not exist,

07:22.850 --> 07:24.519
this does not

07:24.970 --> 07:25.970
exist.

07:27.400 --> 07:28.979
And then we run the double ampersand

07:29.020 --> 07:30.020
and echo works.

07:30.430 --> 07:31.730
We know it will not work.

07:32.350 --> 07:33.967
We had the error for pain because

07:34.450 --> 07:36.067
it could not work properly and it

07:36.190 --> 07:37.930
did not execute that second command

07:39.970 --> 07:41.636
post assessment which operand will

07:41.860 --> 07:43.281
execute command to if command

07:43.930 --> 07:44.930
one is successful.

07:45.280 --> 07:46.629
Is it a command one

07:47.110 --> 07:48.580
single ampersand command to

07:49.150 --> 07:51.399
be command one double ampersand

07:51.400 --> 07:53.259
command to C

07:53.260 --> 07:55.149
command one single ampersands

07:55.150 --> 07:56.439
single command to

07:57.520 --> 07:58.794
command one double command

07:59.410 --> 08:00.410
to

08:01.300 --> 08:03.129
the answer is B command one

08:03.250 --> 08:05.110
double ampersand command to

08:05.470 --> 08:07.449
this operation will only execute

08:07.450 --> 08:08.822
command to if command one is

08:09.160 --> 08:10.924
successful and similar to the double

08:11.230 --> 08:12.553
play. This is a very useful

08:13.240 --> 08:14.906
way to be able to control the flow

08:15.100 --> 08:16.959
of data and help

08:17.140 --> 08:19.089
identify commands

08:19.090 --> 08:20.379
that should be running properly and

08:20.380 --> 08:21.309
should not.

08:21.310 --> 08:23.410
The single ampersand is used for

08:23.620 --> 08:25.779
its own specific ways and Windows

08:25.780 --> 08:26.809
and Linux not to help

08:27.610 --> 08:28.750
with the command flow.

08:29.170 --> 08:30.885
The single ampersand single pipe is

08:31.000 --> 08:32.889
not a valid combination of these

08:32.890 --> 08:34.599
characters, and the double pipe will

08:34.600 --> 08:36.021
only execute command to if it

08:36.460 --> 08:38.409
is unsuccessful for command one

08:39.520 --> 08:40.599
or two. In this video we learned

08:40.600 --> 08:42.639
what Peiping is used for, but single

08:42.640 --> 08:44.529
and double pipes do not understood

08:44.530 --> 08:46.239
the single ampersand in the double

08:46.240 --> 08:48.070
ampersand operands and

08:48.190 --> 08:49.719
how we can use them at the command

08:49.720 --> 08:50.769
line to our advantage.

08:51.010 --> 08:52.329
And I hope to see you in the next

08:52.330 --> 08:52.659
video.

