パイプラインで実行された任意のコマンドの実行結果を取得
解決
PIPESTATUS変数 を使用する
$ false | tee -a '/tmp/test' && if [ "${PIPESTATUS[0]}" -eq 0 ]; then true; else false; fi
$ echo $?
1
$ true | tee -a '/tmp/test' && if [ "${PIPESTATUS[0]}" -eq 0 ]; then true; else false; fi
$ echo $?
0
This post is licensed under CC BY 4.0 by the author.