What does if [ $? -eq 0 ] mean for shell scripts?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: There is this line in a shell script i have seen: grep -e ERROR ${LOG_DIR_PATH}/${LOG_NAME} > /dev/null if [ $? -eq 0 ] 回答1: 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 . 回答2: $? is the exit status of the most recently-executed command; by convention, 0