When is useful use "silent" for tty?
tty --help command is executed it shows
tty --help Usage: tty [OPTION]... Print the file name of the terminal connected to standard input. -s, --silent, --quiet print nothing, only return an exit status --help display this help and exit --version output version information and exit
tty -s is executed it returns nothing
- When is useful use silent for
#!/bin/sh # Script that is run regularly from cron, # but also sometimes from the command line. interactive=false if tty -s; then echo 'Running with a TTY available, will output friendly messages' echo 'and may be interactive with the user.' interactive=true fi # etc.
In short, it provides a way of testing whether a TTY is attached to the current shell session’s standard input stream, which indicates that the script may be able to interact with a user by reading from the standard input stream. You can also do this using the test
[ -t 0 ], or the equivalent
test -t 0, which is true if fd 0 (standard input) is a TTY.
Don’t write the terminal name; only the exit status is affected
when this option is specified. The -s option is deprecated in
favor of the “test -t 0” command.