Hello there, you beautiful people.
And welcome to part three.
Our final part of our discussion on piping.
Now, in part number one, you learned about the basic concepts of piping and you saw that piping is
all about connecting the standard output of one command to the standard input of another command.
And in part two, you saw how you can actually pass data through your pipeline, but also take snapshots
of the data as it flows through and save those snapshots into a file using something called the T command.
Now the T command is really useful because by doing normal redirection you break your pipeline, but
by using the t command, you can save data but still keep your pipeline flowing.
Now, in part number three, we're going to take that understanding of piping to a whole new level using
something called the x args command.
Now, remember, piping is all about connecting the standard output of one command to the standard input
of another command.
Now, not all commands actually even accept standard input.
Some only accept command line arguments.
And that's exactly where the x args command comes in.
The X Command allows you to convert piped data into command line arguments for commands that only accept
command line arguments so that you can keep your pipe going without having to break it at any point.
So the Exile's Command is that missing piece.
It's going to make your pipelines basically indestructible.
So we're going to teach you how to use that.
And then we're also going to have a summary of piping start to finish.
So make sure that these concepts really, really sink in.
By the end of this video, you're going to be the master of piping concepts after you've probably received
the most comprehensive explanation of it that you'll be able to find anywhere on the Internet.
So there we are, guys.
Let's go ahead and jump right over now into Ubuntu and see this stuff in practice.
Okay.
So let's take a look at how the x args command works.
Let's say that we are again playing around with the date command, for example, and we're getting the
date that's coming out of our system now.
What do you think will happen if we take the date command and we pipe it into Echo?
Now, remember, Echo is very simple.
If I just take echo when I say give echo hello, it'll just say hello back.
So what do you think will happen if I take the date command and pipe that into echo?
Well, you might think that when I press when I press enter the date command will pass on the date into
Echo and it'll spit out the date right and wrong.
Actually, what happened is Echo doesn't accept standard input.
So what happened here, this is a common mistake, actually, that people make when using pipelines
for the first time.
They try to pipe things into Echo.
Now, Echo doesn't accept standard input.
In fact, it only accepts command line arguments.
So if I try to do this and I type to echo, hello again.
Even though I'm piping with the date command into it, if I go ahead and press enter, you can see that
it's only processed its command line arguments.
So the question becomes how could we pass the data from our pipeline into a command that doesn't accept
standard input?
Well, the key is to convert the data from standard input into command line arguments so the command
can continue to work like normal.
So the way that you do that is that instead of pie, instead of piping it into echo directly, you pipe
it into something called the x args command.
Now the x args command will convert the data from standard input and it will put it instead into command
line arguments.
So now I do echo, so I basically put it into x args and then give x args echo to work with.
When I press enter now you can see that now it echoes out the date.
Isn't that cool now?
Now I can also give Echo its own its own command line argument, so I could give it also hello.
And what will happen is it will now process both, except it will process its own command line arguments
first.
So that's something to bear in mind.
But it did indeed echo both of them out, which is a lot better than we had before.
Now.
Now we can actually continue to pipe down because the data that comes out is still on standard output.
So basically x args is like a little plaster or a little fix for when for when a command does not accept
standard does not accept standard input, but only accepts command on arguments.
You can use x args to get around the problem and continue doing your piping.
So let's say that we wanted for it to echo out just the day of the week.
What we could do is we could say date pipe that into the command just like we've been doing a million
times.
Tell it that the delimiter is a space.
Tell it that we want the first field and then you could pipe that into echo.
Now, remember, this isn't going to work because Echo doesn't accept standard input.
So we convert the data from standard input into command line arguments using x args.
Give tell x args.
Hey, we want you to work with echo and now we'll see that it pops out the day of the week, which is
Monday.
So let me give you a bit of an example where this might take you, okay?
This this x args ability, what it might be able to do for you.
So for example, if we take our full data text file, we've got some data in here.
Let me just create a new document here.
I'm going to call it and press control and SX to save.
Yep, that works.
I'm going to call it delete me dot txt so I can make that file.
I've called it delete text.
Now when we look we've got a new file in here called delete my text.
Now there's a command that you'll be coming onto later in the course in the, in the section, all about
navigating the file system and things like that, which is the section after this one.
But there's a command in there called the M command.
Now the R command stands for remove.
It's the command that delete stuff and if I type delete me dot txt and I click enter watch on the left.
Watch.
Just over here you'll notice that the file has just been deleted.
Okay, so you notice here that we actually gave the ah m command a command line argument.
We typed it on the command line, we gave it a file name.
Now what we might want to do is we might want to have another file over here.
Okay.
Called files to delete txt so files to delete txt and in there I'm going to give it the the names of
full data and today dot txt.
So if I put that in there full date txt and we're also going to have what was the other one today dot
txt.
So we've got a file that contains those two names.
Okay.
Now we can read that file out using the cat command.
You've seen this before.
So if I do the cat command and I say files to delete, you see how it gives me the output?
Now I can't just pipe that information into the m command.
Nothing will happen.
Okay, because the RRM command only accepts command line the command line arguments.
But what I can do is I can read the data and we clear the screen.
What I can do is I can read the data from files to delete these file names and pass it into x args.
Now x args is going to convert that data into command line argument.
For the rim commander.
The rim command does accept command line arguments.
So when we do that, notice if I just pipe directly to the rim command, it doesn't work.
It says it's missing an operand, it's missing a command line argument.
But if I type it into the x args command instead and then type M, watch what happens now over at the
left when it's at the command, the files got deleted because now the ah m command could work.
What effectively happened?
It was as if we wrote our m today dot txt and full date SDA actually the other way around because the
file they were written in the other way around in the file it's as if we did this it as if we wrote
out this command, this command here, but instead we just read the file and piped the contents to another
command.
So you can see that this is how you might potentially use the X Command just as a bit of an example,
rather than you just using the date command and echo all the time.
So over the past three videos we've covered a whole lot of stuff.
So let's just try and summarize it all together in one place so that you can feel confident that you've
got it all.
First of all, you learn that piping is a process that connects the standard output of one command to
the standard input of another.
And by the way, if you ever see these two words in orange, stand out an STD in from now on, you know,
that means standard output and standard input respectively.
And STD error is standard error.
Okay.
So if you ever see those things around, so piping connects the standard output of one command to the
standard input of another redirection of standard output breaks pipelines.
So if you're making a pipeline and you do some redirection, you've broken your pipeline, you could
the pipeline from that point on will no longer work.
So standard output has just been redirected into a file by default.
It can't be continued to be passed down the pipeline.
That is unless you use the PT command.
So if you want to save a data snapshot without breaking your pipeline, use the PT command instead and
that will make a basically an imaginary T-junction, just like you might find in pipes of water in your
pipeline so that you can save your data and also have it continue on through the pipeline at the same
time.
Now, if a command doesn't accept standard input, then as we know, piping connect standard output
to standard input.
So how can you still use that command in your pipeline?
Well, if you still want to pipe to it, even if it doesn't accept standard input, as long as the command
accepts command line arguments, you can use the x args command instead and commands that you use with
the x args command can also still have their own command line arguments besides the ones that you pipe
to it so you can still pipe data to it.
You can still pipe data as command on arguments and also give it its own arguments right there on the
command line.
But just understand that the ones that you type to it on the command line will be processed first.
So that's a whole bunch of stuff, guys.
This really is the most important part of getting good at the Linux command line.
If you can understand and you feel confident in what you've learned in the last three videos about piping,
you have unlocked the crown jewel of using the Linux command line and you should be massively proud
of yourself.
And if you haven't, then just go back.
Watch these videos as many times as it takes for you to get it down.
Take some notes, practice, try stuff out, because I promise you the effort will be worth it.
And I'm really proud of you for actually making it this far, and so should you as well.
Now, up next, we're going to show you a little trick that's going to make your use of the command
line a whole lot easier.
And we're going to show you how you can use something called aliases to save your command pipelines
with easy to remember names so they can be just used much easier later on.
So once you've written a pipeline, you don't have to write it again.
Just use the name and it will come up without any errors.
So for all that good stuff to learn about aliases and making shortcuts, I'll see you in the next video.