Bird
0
0

What is wrong with this command if the goal is to redirect both stdout and stderr to log.txt?:

medium📝 Troubleshoot Q7 of 15
Bash Scripting - Error Handling
What is wrong with this command if the goal is to redirect both stdout and stderr to log.txt?:

command &> log.txt
AThe '&>' operator is not supported in all shells, causing compatibility issues
BThe filename must be preceded by a dash '-'
CThe command should use '2>&1 > log.txt' instead
DThe command is missing a semicolon at the end
Step-by-Step Solution
Solution:
  1. Step 1: Understand '&>' operator

    '&>' redirects both stdout and stderr but is a bash extension.
  2. Step 2: Identify compatibility issue

    Not all shells (like sh) support '&>', so it may fail.
  3. Final Answer:

    The '&>' operator is not supported in all shells, causing compatibility issues -> Option A
  4. Quick Check:

    Use portable syntax for compatibility [OK]
Quick Trick: Avoid &> for portability; use > file 2>&1 instead [OK]
Common Mistakes:
MISTAKES
  • Assuming &> works in all shells
  • Misplacing redirection operators
  • Adding unnecessary punctuation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes