Получение значения

Простые типы / Логический тип

#bash has no boolean type: a condition is a command and its exit code,
#0 means true (success), any other number means false

name="Alex"
#the result is kept as the word true or false
if [[ -n "$name" ]]; then
    nameExists=true
else
    nameExists=false
fi
#nameExists is "true"

num=7
#(( )) compares numbers; cond && a || b runs b also when a fails,
#an assignment never fails, so here it is a safe short if-else
(( num == 10 )) && isTen=true || isTen=false
#isTen is "false"

#$? is the exit code of the last command: 0 is true
[[ -n "$name" ]]
code=$?
#code is 0

echo "nameExists is $nameExists"
echo "isTen is $isTen"
echo "code is $code"