Bird
0
0

You want to store the number of files in your home directory in a variable file_count. Which command correctly uses command substitution to do this?

hard🚀 Application Q15 of 15
Bash Scripting - Quoting and Expansion
You want to store the number of files in your home directory in a variable file_count. Which command correctly uses command substitution to do this?
Afile_count=$(ls ~ | wc -l)
Bfile_count=`ls ~ wc -l`
Cfile_count=$(ls ~ wc -l)
Dfile_count=ls ~ | wc -l
Step-by-Step Solution
Solution:
  1. Step 1: Understand the command to count files

    To count files, we list them with ls ~ and pipe to wc -l to count lines (files).
  2. Step 2: Use correct command substitution syntax

    file_count=$(ls ~ | wc -l) correctly uses $(ls ~ | wc -l) to run the full command and store output in file_count. The other options miss the pipe or fail to use command substitution.
  3. Final Answer:

    file_count=$(ls ~ | wc -l) -> Option A
  4. Quick Check:

    Use $() with full command and pipe inside [OK]
Quick Trick: Use $() with full command including pipes for substitution [OK]
Common Mistakes:
MISTAKES
  • Missing pipe between commands
  • Using backticks without pipe
  • Assigning command without substitution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes