Skip to content

Detect TTY, pipe, or redirect

Tell whether stdout is a terminal, a pipe, or a redirection.

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
}