I know this will sound pedantic, but $?
is not a variable, it is a value. ?
is the name of the variable, placing $
at the front gives the value.
Now you can search for ?
in man bash
:
Expands to the exit status of the most recently executed foreground pipeline.
It is often tested unnecessarily. if
and while
statements in bash
(and most shells) test for success(true) or failure(false). Success is where the value of ?
is 0, and failure when it is some other number (which has the range 1-255). !
means "not", as in many languages, and inverts the truth:
while ! host google.com>/dev/null
do
sleep 3
done
echo "You are now connected to internet"
(I had to use echo
, not sure where say
comes from, Perl?)