管道符左边命令的输出作为管道符右边命令的输入
连续使用管道意味着第一个命令的输出会作为第二个命令的输入,
第二个命令的输出又会作为第三个命令的输入 以此类推
例子
[jl@localhost 文档]$ cat test.sh
#!/bin/sh
sa="hello"
echo $sa
echo "the program $0 is now running"
echo "the first parameter was $2"
echo "the first parameter was $1"
echo "the parameter list was $*"
echo "the user home directory is $HOME"
echo "please enter a new ddd"
read sa
echo $sa
echo "the script is now over"
exit 0[jl@localhost 文档]$ cat test.sh|grep echo|wc -l
9
[jl@localhost 文档]$
这条命令用了两个管道,第一个管道将cat命令的输出送给grep命令 ,
grep命令找出含有echo的所有行,
[jl@localhost 文档]$ cat test.sh|grep echo
echo $sa
echo "the program $0 is now running"
echo "the first parameter was $2"
echo "the first parameter was $1"
echo "the parameter list was $*"
echo "the user home directory is $HOME"
echo "please enter a new ddd"
echo $sa
echo "the script is now over"
[jl@localhost 文档]$
[jl@localhost 文档]$ cat test.sh|grep echo|wc -l
9
第二个命令讲grep的输出送给wc命令,
wc命令统计出筛选后的行数
例 2
找出系统中有多少个用户正在使用bash
[jl@localhost 文档]$ cat /etc/passwd|grep /bin/bash
root:x:0:0:root:/root:/bin/bash
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
jl:x:500:500:jl:/home/jl:/bin/bash
[jl@localhost 文档]$
[jl@localhost 文档]$ cat /etc/passwd|grep /bin/bash|wc -l
4