Bird
0
0

Given this script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - Variables
Given this script snippet:
filename="report"
echo "File: $filename.txt"

Why does it not print File: report.txt as expected?
ABecause echo cannot print variables with dots
BBecause .txt is treated as a command
CBecause $filename.txt looks for variable named filename.txt which is undefined
DBecause variable names cannot contain letters
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable expansion with suffix

    Using $filename.txt makes bash look for variable named filename.txt, which does not exist.
  2. Step 2: Fix with braces

    Using ${filename}.txt correctly expands filename and appends .txt.
  3. Final Answer:

    Because $filename.txt looks for variable named filename.txt which is undefined -> Option C
  4. Quick Check:

    Braces needed to separate variable name from suffix = A [OK]
Quick Trick: Use braces when adding dot or special chars after variable [OK]
Common Mistakes:
MISTAKES
  • Thinking dot is part of variable name
  • Assuming echo can't print dots
  • Ignoring variable name rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes