Skip to content
qianfan edited this page Oct 17, 2024 · 2 revisions

参考下面的脚本:

#!/bin/sh

/usr/bin/echo 'hello world' | tr ' ' ':' | awk -F':' '{print $2}'

使用 rptree 查看执行情况:

$ rptree -- sh ./pipe.sh 
world

Running process tree generated by rptree dc90f6d215a52aeaee59
0.000 [5887] rptree -- sh ./pipe.sh
|.... 0.000 [5888] sh ./pipe.sh
    |.... 0.001 [5889] /usr/bin/echo 'hello world'
    |.... 0.001 [5890] tr ' ' :
    |.... 0.001 [5891] awk -F: '{print $2}'

$() 不同, 没有额外 fork, 进程是串行运行的.

Clone this wiki locally