Bird
0
0

What will be the output in report.txt after running this script?

medium📝 Command Output Q5 of 15
Bash Scripting - File Operations in Scripts
What will be the output in report.txt after running this script?
printf "Line1\n" > report.txt
printf "Line2" >> report.txt
echo "Line3" >> report.txt
ALine1\nLine2\nLine3\n
BLine1\nLine2\nLine3
CLine1Line2Line3
DLine1\nLine2Line3\n
Step-by-Step Solution
Solution:
  1. Step 1: Check each command's output

    First printf writes 'Line1' plus newline. Second printf writes 'Line2' without newline. echo writes 'Line3' plus newline.
  2. Step 2: Combine outputs carefully

    File content: Line1\nLine2Line3\n because Line2 and Line3 are on same line.
  3. Final Answer:

    Line1\nLine2Line3\n -> Option D
  4. Quick Check:

    printf without \n does not add newline [OK]
Quick Trick: printf needs explicit \n for newline [OK]
Common Mistakes:
MISTAKES
  • Assuming printf adds newline automatically
  • Confusing echo and printf newline behavior
  • Ignoring echo adds newline

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes