Bird
0
0

You want to store the number of files in the current directory into a variable count. Which command correctly does this using command substitution?

hard🚀 Application Q8 of 15
Bash Scripting - Quoting and Expansion
You want to store the number of files in the current directory into a variable count. Which command correctly does this using command substitution?
Acount=`ls | wc -l`
Bcount=$(ls | wc -l)
CBoth A and B
Dcount=ls | wc -l
Step-by-Step Solution
Solution:
  1. Step 1: Understand command substitution for pipeline

    Both backticks and $() can capture output of piped commands.
  2. Step 2: Check syntax correctness

    Options A and B correctly assign the output of ls piped to wc -l to count.
  3. Final Answer:

    Both A and B -> Option C
  4. Quick Check:

    Backticks or $() capture piped output = Both A and B [OK]
Quick Trick: Use backticks or $() to capture piped command output [OK]
Common Mistakes:
MISTAKES
  • Assigning without command substitution
  • Missing backticks or $()
  • Using wrong syntax with pipes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes