Bird
0
0

In bash scripting, what does the operator 2>&1 achieve when used in a command?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Error Handling
In bash scripting, what does the operator 2>&1 achieve when used in a command?
ARedirects standard input (stdin) to standard error (stderr)
BRedirects standard output (stdout) to a file named '1'
CRedirects both stdout and stderr to separate files
DRedirects standard error (stderr) to the same destination as standard output (stdout)
Step-by-Step Solution
Solution:
  1. Step 1: Understand file descriptor numbers in bash

    File descriptor 1 is stdout, and 2 is stderr in bash.
  2. Step 2: Analyze the redirection operator '2>&1'

    This means redirect stderr (2) to wherever stdout (1) is currently going.
  3. Final Answer:

    Redirects standard error (stderr) to the same destination as standard output (stdout) -> Option D
  4. Quick Check:

    2>&1 = Redirect stderr to stdout [OK]
Quick Trick: 2>&1 merges error output into standard output stream [OK]
Common Mistakes:
MISTAKES
  • Confusing stdout and stderr file descriptors
  • Thinking 2>&1 redirects stdout to stderr
  • Assuming it creates a file named '1'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes