From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Piping

Piping

- [Instructor] If Linux was a superhero, its superpower would be pipes. Pipes let us take the output of one program, and feed it to the input of another. We can create exceptionally sophisticated programs simply by piping commands together. And, like almost everything else that works from the terminal, pipes also work in a script. Let's code up an example script using pipes. If I do pipe.sh, we'll touch it. Change mode 755, pipe.sh. Then we do atom pipe.sh. What we want is to display the first three files in our current directory in descending alphabetical order. Each file should also have a count. This kinda thing could easily be several hours of programming, or just a few lines of script code. Let's go ahead and put in our shebang. Then we got FILES=, and this is the backtick, not the single quote, but the backtick, and then we're gonna do an ls -1, then we use the pipe, which is the character over the backslash, then we do a sort -r, the pipe again, then we do a head -3, and then…

Contents