Victor
Victor

Reputation: 1345

Can anyone explain to me what the purpose of /dev/tty

Can anyone explain what the purpose or how to use /dev/tty

Upvotes: 4

Views: 2442

Answers (3)

naka
naka

Reputation: 1

If stdin is already set to be a pipe, you may use /dev/tty to emulate reading from the controlling input terminal device.

For example:

echo ~/.profile ~/.bashrc | xargs sh -c 'vim "$@" </dev/tty' dummy_script_name
# :qa  # quit all files

See: After doing grep and passing it to vim then quitting, why am I experiencing this weird console malfunctioning?

Upvotes: 0

Fred Foo
Fred Foo

Reputation: 363547

It allows a program to connect to its "controlling terminal," if any, even if stdin, stdout and stderr have been redirected away from it. A common use is to request a password from the user.

Upvotes: 1

Nemo
Nemo

Reputation: 71525

You can start with the POSIX spec. From there, read about the "controlling terminal" of a process.

But just for example... /dev/tty is how a command like "ssh" can read your password even if its standard input comes from somewhere else:

tar cf - . | ssh dest 'tar xf -'

If ssh decides to prompt you for a password, it will read it from /dev/tty instead of stdin.

Conceptually, /dev/tty is "the keyboard and text terminal". More or less.

Upvotes: 6

Related Questions