Bird
0
0

Which of the following is the preferred syntax for command substitution in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - Quoting and Expansion
Which of the following is the preferred syntax for command substitution in bash?
Aecho `ls -l`
Becho $(ls -l
Cecho $[ls -l]
Decho $(ls -l)
Step-by-Step Solution
Solution:
  1. Step 1: Identify valid command substitution syntax

    Command substitution uses either backticks `command` or $(command). Both the backtick version and the incomplete $() version look valid at first.
  2. Step 2: Check for best practice and syntax correctness

    echo `ls -l` uses backticks which are valid but less readable and harder to nest. echo $(ls -l) uses $() which is modern and preferred. echo $[ls -l] uses invalid syntax with $[]. echo $(ls -l misses closing parenthesis.
  3. Final Answer:

    echo $(ls -l) -> Option D
  4. Quick Check:

    Use $() for clear command substitution [OK]
Quick Trick: Use $() for command substitution, it's clearer and nestable [OK]
Common Mistakes:
MISTAKES
  • Using $[] which is arithmetic expansion, not command substitution
  • Missing closing parenthesis
  • Confusing backticks with other symbols

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes