When is useful use "silent" for tty?

If the 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

Therefore when tty -s is executed it returns nothing

Question

  • When is useful use silent for tty?

I thought maybe in a script it would not show any output but the return code would contain the value it would normally show. I tested that but it doesn’t. Just shows a 0 return.

tty -s
echo “$?”
0

Hi Manuel,
I looked at the source code

It does indeed display nothing with the -s option.
but i think it returns 0 if the terminal is a tty
and 1 if the terminal is not a tty

however @pdecker tried it and it returned zero… does that mean he was using a tty terminal?
I am not sure
Regards
Neville

In Termux

$ tty -s
$ echo "$?"
0
$ tty
/dev/pts/0

So it thinks /dev/pts0 is a tty ??

1 Like

Hello to all.

Pls let me try your suggestions in both environments, GUI and server.

I am using the Window Terminal available by default on Ubuntu Desktop and Fedora Workstation. So not server environment, but it is going to be test it.

Best to all.

2 Likes