I want to experiment with terminals and colored output, but at the same time I want to make stdout/stderr redirection to file possible without having to deal with these escape sequences.
Is there any way to check whether stderr is connected to a terminal from within a shell script?
The file descriptor for standard error, stderr, is 2. The
testor[command (which is often a shell built-in) has an option,-t, to test whether a file descriptor is connected to a terminal: