commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Oddly, the isatty(3) glibc C call doesn't have a direct analogue as a command 'isatty(1)'. All is not lost as you can use test(1).
For example, your script might be run from a tty or from a GUI menu item but it needs to get user-input or give feedback. Now your script can test STDIN with 'isatty 0' or STDOUT with 'isatty 1' and use xmessage(1) if the tty is not available.
The other way to test for this is with 'tty -s' - but that's only for STDIN.
There are 2 alternatives - vote for the best!
Exit with error if script is not run in a terminal
If your script needs to be run in a terminal, this line at the top will stop it running if you absent-mindedly double-click the icon, perhaps intending to edit it. (Of course this won't help with scripts that run in the background.)
If you can do better, submit your command here.
You must be signed in to comment.