Since you are comparing numbers, you can use an arithmetic expression that allows you to simplify parameter processing and comparison:
wget -q --tries=10 --timeout=20 --spider http://google.com if (( $? != 0 )); then echo "Sorry you are Offline" exit 1 fi
Note that instead of -ne you can just use != . In an arithmetic context, we donβt even need to add $ to the parameters, i.e.
var_a=1 var_b=2 (( var_a < var_b )) && echo "a is smaller"
works great. However, this does not apply to the special parameter $? .
The construct (( ... )) is available in Bash, but the POSIX shell specification is not required (referred to as a possible extension, though).
All that is said, is it better to avoid $? in general, in my opinion, how to answer in Cole and Stephen to answer .
Benjamin W. Jun 04 '16 at 21:29 2016-06-04 21:29
source share