Chinaunix

标题: [bash] bash 管道的三种形式 [打印本页]

作者: yjh777    时间: 2016-01-15 09:37
标题: [bash] bash 管道的三种形式
cmd1 | cmd2     #cmd1 写管道 cmd2 读; cmd2是进程组首进程,$? 是 cmd2 的返回值 (如果没有 set -o pipefail)

cmd1  >    >(cmd2)  #cmd1 写 cmd2 读; cmd1 是进程组首进程,$?是cmd1的返回值
cmd1  <    <(cmd2)  #cmd2 写 cmd1 读; cmd1 是进程组首进程,$?是cmd1的返回值


-------------------------------------------------------
还有
*  | 是匿名管道,没有办法看到
*  >(cmd)   <(cmd)  可以看到:
  1. $ ls  -l   <(:)  >(:)  >(:)  <(:)
  2. lr-x------. 1 yjh yjh 64 1月  15 09:33 /dev/fd/60 -> pipe:[11702476]
  3. l-wx------. 1 yjh yjh 64 1月  15 09:33 /dev/fd/61 -> pipe:[11702474]
  4. l-wx------. 1 yjh yjh 64 1月  15 09:33 /dev/fd/62 -> pipe:[11702472]
  5. lr-x------. 1 yjh yjh 64 1月  15 09:33 /dev/fd/63 -> pipe:[11702470]
复制代码
* 他们都是单向管道,从 ls -l 结果可以看出,要么只读 要么只写
作者: 陈卓文    时间: 2016-01-15 16:41
大神来个具体命令操作可好?不懂啊
作者: yjh777    时间: 2016-01-15 20:06
把 cmd1 cmd2 替换成你希望的命令 试试
作者: yjh777    时间: 2016-01-15 20:11
ls | tee log
ls > >(tee log)
grep -wf <(pgrep nfsd) /proc/nfsd/lock
作者: waker    时间: 2016-01-15 20:31
学习了!
作者: yjh777    时间: 2016-01-21 18:54
更正一下 | 其实也有办法看到的


u0_a54@msm8916_32:/ $ ls|ls -l /proc/self/fd
lr-x------ u0_a54   u0_a54            2016-01-21 18:49 0 -> pipe:[174558]
lrwx------ u0_a54   u0_a54            2016-01-21 18:49 1 -> /dev/pts/0
lrwx------ u0_a54   u0_a54            2016-01-21 18:49 2 -> /dev/pts/0
lr-x------ u0_a54   u0_a54            2016-01-21 18:49 3 -> /proc/791/fd
lr-x------ u0_a54   u0_a54            2016-01-21 18:49 8 -> /dev/__properties__
u0_a54@msm8916_32:/ $




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2