Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Last active June 30, 2025 18:31
Show Gist options
  • Save bendrucker/cea3628c7e3e26b740ee708116b989c2 to your computer and use it in GitHub Desktop.
Save bendrucker/cea3628c7e3e26b740ee708116b989c2 to your computer and use it in GitHub Desktop.
Detect interactivity in a shell.
#!/bin/bash
[ -t 0 ] && stdin_tty="yes" || stdin_tty="no"
[ -t 1 ] && stdout_tty="yes" || stdout_tty="no"
[ -t 2 ] && stderr_tty="yes" || stderr_tty="no"
echo "- stdin TTY: $stdin_tty"
echo "- stdout TTY: $stdout_tty"
echo "- stderr TTY: $stderr_tty"
echo "- TERM: ${TERM}"
echo "- COLORTERM: ${COLORTERM}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment