2017-07-03 136 views
0

我试图停止处理带IF条件的shell脚本。不从shell脚本中退出

output7=${output7##*[[:space:]]} 

if [[ $output4 -gt 0 && $output5 -gt 0 && $output6 -gt 0 && $output7 -gt 0 ]] 
then echo 'Success' 
else echo 'Failure'|| exit 0 
fi 

echo 'Process Completed' 

它正在打印下面的消息,但下一条语句也正在执行。输出是:

Failure 
Process Completed 

任何人都可以告诉我为什么它不退出脚本。

回答

2

这里的问题在于你说“如果echo 'Failure'失败,然后exit 0”,这不是你想要的。你会想要

echo 'Failure' 
exit 1 

改为。整个部分的地道Bash风格为:

if [[ $output4 -gt 0 ]] && [[ $output5 -gt 0 ]] && [[ $output6 -gt 0 ]] && [[ $output7 -gt 0 ]] 
then 
    echo 'Success' 
else 
    echo 'Failure' 
    exit 1 
fi