Bash:pipe道输出到后台进程?

我想把一个过程放到后台,然后多次向它传输数据。 例如:

cat & # The command I want to write into cat_pid=$! # Getting the process id of the cat process echo hello | $cat_pid # This line won't work, but shows what I want to # do: write into the stdin of the cat process 

所以我有PID,我怎么写入这个过程呢? 我会打开以不同的方式启动猫过程。

另外,我在Mac上,所以我不能使用/proc 🙁

首先,创建一个管道:

 $ mkfifo pipe 

其次,从管道输入开始你的猫进程:

 $ cat <pipe & [1] 4997 

现在,发送数据到管道:

 $ echo "this is a test" >pipe $ this is a test 
 mkfifo .pipe cat < .pipe & echo hello > .pipe