Multiple choice technology programming languages

Following test option may be used to check whether the stdin in a given script is a terminal

  1. [ -t 0 ]

  2. [ -t 1 ]

  3. [ -T 0 ]

  4. [ -T 1 ]

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Bash, the -t test operator checks if a file descriptor is opened on a terminal. File descriptor 0 represents standard input (stdin). Therefore, [ -t 0 ] correctly checks if stdin is a terminal. Option [ -t 1 ] checks stdout, while -T is not a valid test operator for this purpose.