课程: Learning Linux Shell Scripting
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。