Я пытаюсь проверить, установлены ли определенные переменные и завершается ли ping с 0. Когда я делаю
var=1 #set for later
#"If" checks exit status correctly
if ping -c 1 an-inaccessible-thing
then
echo T
else
echo F
fi
#returns F
#"if" does not like the program in the [[ ]]
if [[ -n $var && ping -c 1 an-inaccessible-thing ]]
then
echo T
else
echo F
fi
#returns this error for obvious reasons
-bash: conditional binary operator expected
-bash: syntax error near `-c'
#if runs its test on the output of the shell, not its exit code.
if [[ -n $var && $(ping -c 1 an-inaccessible-thing) ]]
then
echo T
else
echo F
fi
#returns T, probably because it's being evaluated with -n and no the exit code
, как я могу проверить программы выхода из кода в двойных квадратных скобках?