Bird
0
0

Why is it recommended to use IFS= read -r instead of just read when reading lines in bash?

hard🧠 Conceptual Q10 of 15
Bash Scripting - File Operations in Scripts
Why is it recommended to use IFS= read -r instead of just read when reading lines in bash?
ATo speed up the reading process
BTo read multiple lines at once
CTo automatically convert lines to uppercase
DTo prevent trimming of leading/trailing whitespace and disable backslash escapes
Step-by-Step Solution
Solution:
  1. Step 1: Understand the effect of IFS= and -r

    Setting IFS= disables word splitting and trimming; -r disables backslash escape interpretation.
  2. Step 2: Recognize why this is important

    This ensures lines are read exactly as they appear, preserving spaces and backslashes.
  3. Final Answer:

    To prevent trimming of leading/trailing whitespace and disable backslash escapes -> Option D
  4. Quick Check:

    Preserve line integrity = B [OK]
Quick Trick: Use IFS= and -r to read raw lines exactly [OK]
Common Mistakes:
MISTAKES
  • Thinking it speeds reading
  • Expecting uppercase conversion
  • Believing it reads multiple lines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes