3 ms·
The isatty(3) system call will let you know if STDOUT is a terminal. There are two cases when you should definitely take advantage of isatty: 1) Your tool, by
by jewel 11y ago
The isatty(3) system call will let you know if STDOUT is a terminal.
There are two cases when you should definitely take advantage of isatty:
1) Your tool, by default, outputs in color.
2) Your tool, by default, outputs progress, which you keep on a single line by overwriting by outputting \r.
Both of these potentially annoying when your command is used in a script, and especially annoying if they are called from cron.
In other cases I agree with you, getting too creative violates the principle of least surprise.
- nitrogen 11y agoIn the case of 1/color, I respectfully request that all toolmakers leave an option for forcing color even if STDOUT is not a tty, so I can, for example, use less -R on colorized logs and still get element highlighting.
- jzwinck 11y agoIf you get stuck with a tool lacking such an option, you can run it under "script" to trick it. I recall other programs to do similar using a pseudo-TTY but I can't recall their names now (and with a name like "script" it was a miracle I got that one).