How can I detect if my shell script is running through a pipe?

How do I detect from within a shell script if its standard output is being sent to a terminal or if it’s piped to another process?

The case in point: I’d like to add escape codes to colorize output, but only when run interactively, but not when piped, similar to what ls --color does.

6 Answers
6

Leave a Comment