这是什么,如果[$? -eq 0]意味着shell脚本? [英] What does if [ $? -eq 0 ] mean for shell scripts?
本文介绍了这是什么,如果[$? -eq 0]意味着shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有是此行的shell脚本我已经看到:
的grep -e错误$ {LOG_DIR_PATH} / $ {LOG_NAME}>的/ dev / null的
如果[$? -eq 0]
解决方案
它检查返回值( $?
)的的grep
。在这种情况下,它比较它与0(成功)。
当你看到这样的事情(检查的grep的返回值),它的检查,以确定是否检测到特定的字符串通常。虽然重定向到的/ dev / null的
是没有必要的,同样的事情可以通过完成 -q
。
There is this line in a shell script i have seen:
grep -e ERROR ${LOG_DIR_PATH}/${LOG_NAME} > /dev/null
if [ $? -eq 0 ]
解决方案
It's checking the return value ($?
) of grep
. In this case it's comparing it to 0 (success).
Usually when you see something like this (checking the return value of grep) it's checking to see whether the particular string was detected. Although the redirect to /dev/null
isn't necessary, the same thing can be accomplished using -q
.
这篇关于这是什么,如果[$? -eq 0]意味着shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文