![exec tee 重定向檔案將建立 bash 進程](https://rvso.com/image/1618732/exec%20tee%20%E9%87%8D%E5%AE%9A%E5%90%91%E6%AA%94%E6%A1%88%E5%B0%87%E5%BB%BA%E7%AB%8B%20bash%20%E9%80%B2%E7%A8%8B.png)
像這樣的腳本:
exec &> >(tee -a ./test_tee.log)
ping $1
當腳本在 bash 7603 中執行時,exec 行將建立一個名為 13069 的進程,如下所示:
root 13068 7603 0 17:15 pts/5 00:00:00 bash
root 13069 13068 0 17:15 pts/5 00:00:00 bash // where does it come from
root 13070 13068 0 17:15 pts/5 00:00:00 ping google.com
root 13071 13069 0 17:15 pts/5 00:00:00 tee -a ./test_tee.log
我在bash中執行pid 7603的腳本,pid 13068是腳本,為什麼有pid 13069
答案1
附加進程是一個正在執行的子 shell tee -a ./test_tee.log
。用 確認這一點pstree -p | grep -B 1 '[t]ee'
。
你可以告訴這個子shell代替本身與tee
.將相關行更改為:
exec &> >(exec tee -a ./test_tee.log)