[Linux] Linuxコマンドラインとシェルスクリプトの異常な出力をキャプチャし、ファイルに保存します

 

#!/bin/bash
cat aa.txt > /tmp/error 2>&1 #使用 " 2>&1" 把标准错误 stderr 重定向到标准输出 stdout ;
echo $? #捕获上一条命令的输出 (if 0 正常 else 错误)
ls -l > /tmp/log
echo $?

ファイル/ tmp / log。


#cat / tmp / error  cat:aa.txt:そのようなファイルまたはディレクトリはありません

おすすめ

転載: blog.csdn.net/qq_44065303/article/details/109094600