Bird
0
0

What will be the output of this script if file.txt contains:

medium📝 Command Output Q13 of 15
Bash Scripting - File Operations in Scripts
What will be the output of this script if file.txt contains:
apple
banana
cherry

Script:
while IFS= read -r line; do echo "Fruit: $line"; done < file.txt
AFruit: apple Fruit: banana Fruit: cherry
Bapple banana cherry
CFruit: apple banana cherry
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop reading each line

    The loop reads each line from file.txt separately.
  2. Step 2: Check the echo command

    Each line is printed prefixed with "Fruit: ".
  3. Final Answer:

    Fruit: apple Fruit: banana Fruit: cherry -> Option A
  4. Quick Check:

    Line prefixing with echo = B [OK]
Quick Trick: Each loop iteration prints one line with prefix [OK]
Common Mistakes:
MISTAKES
  • Expecting all lines printed on one line
  • Ignoring the prefix in echo
  • Confusing input and output redirection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes