1
如何從bash腳本生成新的後臺進程並使用fd重定向將當前腳本的stdout/stderr重定向到該進程的stdin?我知道有幾種方法可以實現相同的效果,例如使用命名管道或臨時文件,使用coprocs,或者在子shell中運行整個腳本並將其重定向到其他進程,但是我正在尋找從腳本內部簡單的一行IO重定向,就像我可以這樣做:exec 2>&1
。基本上,我想這樣做(的進程產生的方式是可以改變的,當然):生成進程並將當前bash腳本的輸出重定向到它
#!/bin/bash
zenity --text-info & # The process to receive this script's output
# Do something to redirect this shell's stdout
# to the background process's stdin
echo "something" # This should be read by the background process