Bird
0
0

This script is intended to print the third column of a CSV file:

medium📝 Debug Q7 of 15
Bash Scripting - File Operations in Scripts
This script is intended to print the third column of a CSV file:
while IFS=',' read -r col1 col2 col3; do echo $col3; done file.csv

But it does not work. What is the problem?
AMissing input redirection '<' before file.csv
BUsing read -r disables field splitting
CEcho does not print variables correctly
DIFS should be set after read command
Step-by-Step Solution
Solution:
  1. Step 1: Check how input is provided to while loop

    while loop reads from standard input; file.csv must be redirected with '<'.
  2. Step 2: Identify missing redirection

    Script lacks '< file.csv', so loop reads nothing and prints nothing.
  3. Final Answer:

    Missing input redirection '<' before file.csv -> Option A
  4. Quick Check:

    Use '< file.csv' to feed file into while loop [OK]
Quick Trick: Redirect input with '<' to read file lines in while loop [OK]
Common Mistakes:
MISTAKES
  • Forgetting input redirection
  • Misunderstanding read -r effect
  • Setting IFS incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes