私はその原因を知らない問題に遭遇しました。両方を出力と機能「テスト」からのrsync出力をエコー含むことになる上記の例file_A.txtでなぜ、Teeはすべての出力(Bash)を書きませんか?
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_B.txtには、エコー出力のみが含まれます。どうしてこれなの?あなたは、ストリーム
mytest()
{
echo "This will be printed to the file"
#But the output of rsync will not
rsync -av /path/A /path/B 2>&1
# -----------------------^^^^^^
echo "This will be printed to the file"
}
test
にstderr出力を追加する必要が
私は 'file_B.txt'と' file_A.txt'の両方で同じ出力を得ています。いずれのファイルにもないのは、リダイレクトされていないため、 'rsync'が' stderr'に出力するものだけです。 – jcollado
'test'という関数には十分注意してください。 'test 'という組み込みのコマンドもあります。より一般的に' ['として使われますが、どちらも存在します。あるいは、 'bash'の下では、' test'コマンドは '/ bin'のコマンドですが、あなた自身の目的に' test'を使うことには依然として慎重です。 –