![]() ![]() If not, it will again set the use_color parameter to false. Specifically, the ls code tests whether the terminal actually supports colors. There are many other tests, but this gives you the basics. It will just always send the color.įor those interested in how this is done under Linux, you use the isatty() function. The effect of the -color is to skip the test to know how to handle stdout. Then you can use cgrep instead of grep to always get colors.Ĭheck the manual page of other commands you'd like to keep the colors from as it is not unlikely that they have a similar color option. You could create an alias, though that does it for you. ![]() This is because it detects whether the output is a TTY or not. Notice that for grep you need to use the "always" keyword. In case of the ls and grep commands, they both require the -color command line option for the color to stick even when the command gets piped: So we do want to be able to print colors even to a pipe. There are various potential problems, although frankly in generally this technique works great. But of course, when you use less (or more) you are on the terminal so why not display the colors as expected?! ![]() and therefore a place where the color commands should not be sent because the next processing of the output would likely be badly affected by all the controls, square backet, and other terminal commands.Īctually, those commands are really very specific to the terminal and therefore should not be sent anywhere else. If not, it can generally be assumed that it's a file, a pipe, a variable, etc. The fact is that many tools will check their stdout and determine whether it's a terminal or not. However, you lose those nice colors when you want to use "less" to paginate the results. This is true in this century that computer started to use more and more colors in the console. Whenever I run a command without piping it through less, I generally get colors. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |