junxnone / xwiki

https://junxnone.github.io/xwiki/
0 stars 0 forks source link

Programing Shell ErrorCheck #107

Open junxnone opened 5 years ago

junxnone commented 5 years ago

错误检查

UseCase

if [ $? -ne 0 ]; then
    echo "failed"
    exit 0
else
    echo "succeed"
fi
$ cat 1238|ls
cat: 1238: No such file or directory

$ echo ${PIPESTATUS[0]}${PIPESTATUS[1]}
10

tee 未收集 error log

your_cmd 2>1&|tee your_log.txt

将标准错误(stderr)重定向到标准输出(stdout)

Reference

junxnone commented 4 years ago

junxnone/linuxwiki#23