我遇到了一个我不知道原因的问题。我想最简单的解释方法是通过代码示例:
test ()
{
echo "This will be printed to the file"
#But the output of rsync will not
rsync -av /path/A /path/B
echo "This will be printed to the file"
}
function_calling_test ()
{
test | tee -a "file_B.txt"
}
function_calling_test | tee -a "file_A.txt"
在上面的示例中,file_A.txt将包含echo输出和函数"test"的rsync输出,但file_B.txt将仅包含echo输出。为什么是这样?