Difficulty: Easy
Correct Answer: tty
Explanation:
Introduction / Context:
Interactive sessions in Unix are attached to pseudo-terminals or console devices. Knowing exactly which device your shell is connected to can help with redirection, permission debugging, and multi-user administration.
Given Data / Assumptions:
Concept / Approach:
The tty program writes the file name of the terminal connected to standard input. If the shell is attached to a TTY-like device, it returns a path under /dev; otherwise, it may print 'not a tty' when input is not a terminal.
Step-by-Step Solution:
Verification / Alternative check:
Piping or redirecting input can change behavior; for example, running tty < /dev/null will report not a tty. In an interactive shell, plain tty always prints the device name, confirming its identity purpose.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing 'who am i' with 'tty'; the former prints your login name and terminal line but is less direct than tty's device path output. Also, note that scripts running non-interactively may not have a controlling TTY.
Final Answer:
tty
Discussion & Comments