LFCS · Question #828
In Bash, inserting 1>&2 after a command redirects
The correct answer is C. standard output to standard error. In Bash, the redirection 1>&2 directs standard output (file descriptor 1) to the same destination as standard error (file descriptor 2).
Question
Options
- Astandard error to standard input.
- Bstandard input to standard error.
- Cstandard output to standard error.
- Dstandard error to standard output.
- Estandard output to standard input.
How the community answered
(55 responses)- A2% (1)
- B2% (1)
- C89% (49)
- D7% (4)
Why each option
In Bash, the redirection `1>&2` directs standard output (file descriptor 1) to the same destination as standard error (file descriptor 2).
`1>&2` redirects standard output to standard error, not standard error to standard input.
`1>&2` redirects standard output to standard error, not standard input to standard error.
The `1>&2` redirection explicitly redirects file descriptor 1 (standard output) to file descriptor 2 (standard error). This means any output that would normally go to standard output will instead be sent to standard error, often used for logging both regular and error messages to the same error stream.
To redirect standard error to standard output, the syntax would be `2>&1`.
To redirect standard output to standard input is generally not a direct or useful operation in this context; `1>&0` would be the syntax if that were possible, but standard input is for reading, not writing.
Concept tested: Bash standard I/O redirection
Source: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Redirections
Topics
Community Discussion
No community discussion yet for this question.