# if [ -t 0 ] => stdin is a terminal, use any of the solutions above

# -t | test option may be used to check
# whether the stdin [ -t 0 ] or stdout [ -t 1 ] in a given script is a terminal.

# test for a terminal!

fd=0   # stdin

#  as we recall, the -t test option checks whether the stdin, [ -t 0 ],
#+ or stdout, [ -t 1 ], in a given script is running in a terminal.
if [ -t "${fd}" ]; then
  echo interactive
else
  echo non-interactive
fi

# but
#   if [ -t 0 ] works ... when you're logged in locally
#   but fails when you invoke the command remotely via ssh.
#   so for a true test you also have to test for a socket.

if [ -t "${fd}" ] || [ -p /dev/stdin ]; then
  echo interactive
else
  echo non-interactive
fi
