在 bash 中,有一种方法可以创建一个函数流,如果出现错误,它将阻止下一个函数调用:
IE
function msg_ok {
echo "$(date '+%Y%m%d_%H%M%S'): OK+: $1 $2" | tee -a "/tmp/log_me"
}
function msg_er {
echo "$(date '+%Y%m%d_%H%M%S'): ERR: $1 $2" | tee -a "/tmp/log_me"
}
function msg_check {
tail last_line_of_log | grep "ERR"
exit
}
function first {
msg_check
do_your_thing
msg_er "nothing works"
else
msg_ok "go on to next"
}
function second {
msg_check
do_your_thing
msg_er "nothing works 2"
else
msg_ok "go on to next 2"
}
first
second
third
我的意思是有没有办法以不同的顺序调用第一个第二个和第三个并停止如果之前调用了 msg_er ?