Skip to content

Detect TTY, Pipe, or Redirect

Report whether stdout is attached to a terminal, a pipe, or a redirection so scripts can choose human or machine output.

Language: Shell

Added on: 18th August 2026

in_terminal() {
  [[ -t 1 ]] && return 0 || return 1
}

in_pipe() {
  [[ -p /dev/stdout ]] && return 0 || return 1
}

in_redirection() {
  [[ ! -t 1 && ! -p /dev/stdout ]] && return 0 || return 1
}