Bird
0
0

What is the effect of this command?

medium📝 Command Output Q5 of 15
Bash Scripting - File Operations in Scripts
What is the effect of this command?

exec 3>&1
ARedirects standard error to file descriptor 1
BCloses file descriptor 3
CRedirects standard output to file descriptor 3
DCreates a new file descriptor 3 that points to standard output
Step-by-Step Solution
Solution:
  1. Step 1: Understand exec with file descriptors

    exec 3>&1 duplicates stdout (fd 1) to fd 3, creating a new descriptor.
  2. Step 2: Interpret the effect

    Fd 3 now points to the same place as stdout, allowing later use.
  3. Final Answer:

    Creates a new file descriptor 3 that points to standard output -> Option D
  4. Quick Check:

    exec 3>&1 duplicates stdout to fd 3 [OK]
Quick Trick: exec n>&m duplicates fd m to fd n [OK]
Common Mistakes:
MISTAKES
  • Thinking it closes fd 3
  • Confusing direction of redirection
  • Assuming it affects stderr

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes