Bird
0
0

What will be the output of this script snippet?

medium📝 Command Output Q13 of 15
Bash Scripting - Quoting and Expansion
What will be the output of this script snippet?
files=$(ls /tmp)
echo "$files"
AShows an error because of missing quotes
BPrints the literal string '$(ls /tmp)'
CLists all files and directories inside /tmp one per line
DPrints nothing because variable is empty
Step-by-Step Solution
Solution:
  1. Step 1: Understand command substitution with ls

    The command ls /tmp lists files in /tmp. Using files=$(ls /tmp) stores that output as a string with filenames separated by newlines.
  2. Step 2: Echo the variable with quotes

    Using echo "$files" prints the content of files preserving newlines, so it lists all files and directories one per line.
  3. Final Answer:

    Lists all files and directories inside /tmp one per line -> Option C
  4. Quick Check:

    Command substitution stores output string = list of files [OK]
Quick Trick: Command substitution stores output as string, echo prints it [OK]
Common Mistakes:
MISTAKES
  • Expecting literal command string output
  • Confusing quotes causing errors
  • Assuming variable is empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes