A hassle-free solution consists of using the command tty -s.
This command returnreturns either 0 or 1.
if tty -s; then
echo "I am on a TTY"
else
echo "I am NOT on a TTY"
fi
p.s.: I do not have access to other UNIX man pages. I can guarantee that it works on LinuLinux.