# tty -s deprecated in favor of "test -t 0"
# if tty -s; then echo "interactive"; else echo "non-interactive"; fi

# if [ -t 0 ] works ... when you are logged in locally but
#       fails when you invoke the command remotely via ssh.
# if [ -t 0 ]; then echo "interactive"; else echo "non-interactive"; fi

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

# interactive shell is when you typein 'bash' from your login or another interactive shell.
# and stdin and stdout are terminals.
# to see if yours are terminals (they probably are if you're typing in), run these:

[ -t 0 ] && echo "stdin is a tty"
[ -t 1 ] && echo "stdout is a tty"
