Reputation: 1345
Can anyone explain what the purpose or how to use /dev/tty
Upvotes: 4
Views: 2442
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
Upvotes: 0
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
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