I want to write a shell script that will use colored output when the output is terminal, and normal output when redirected to a file. How can i do this?
Very simple:
if [ -t 1 ]; then echo "Hello, terminal." else echo "Not a terminal." fi
-t checks if the given file descriptor is attached (here 1 = stdout).
-t
Source: https://habr.com/ru/post/981962/More articles:Parsing comments in dot file using python - pythonTypeError: sparse matrix length is ambiguous; to use getnnz () or form [0] when using the RF classifier? - pythonaddFirst class method of ArrayDeque - javaClassification of text documents with random forests - pythonRxJS: How can I do an “if” with Observables? - javascriptHow to determine the folder name for multiple screens (conflict between Nexus 10 and Galaxy Tab 10)? - androidHow to set border-left for navigation menu in css? - htmlGolang memory leak regarding gorout - multithreadingLog in to Perforce from the command line - command-lineUsing a URL scheme to get the background runtime in another application - iosAll Articles