I'm writing a shell script that uses ANSI color characters on the command line.
Example: example.sh
#!/bin/tcsh
printf "\033[31m Success Color is awesome!\033[0m"
My problem is when doing:
$ ./example.sh > out
or
$./example.sh | grep
The ASCII codes will be sent out raw along with the text, mucking up the output and just generally causing chaos.
I'm interested to know if there is a way to detect this so I could disable color for this special case.
I've search the tcsh man pages and the web for a while and have not been able to find anything shell specific yet.
I'm not bound to tcsh, it's our group standard... but who cares?
Is it possible to detect, inside a shell script, if your output is being redirected or piped?