LPIC-1 Shells, Scripting and Data Management Practice Question
Which TWO of the following are valid ways to capture the output of a command into a variable in Bash?
⚠ Common exam trap
LPI often tests the distinction between command substitution syntax and other shell constructs like brace expansion or simple assignment, leading candidates to confuse var=$(command) with var={command} or var=command.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
var=`command`
Both var=`command` (backticks) and var=$(command) (dollar-parentheses) are valid command substitution syntaxes in Bash. While backticks are older and can cause issues with nesting, they are still valid and widely used. Option B uses braces, which is not a valid syntax. Option D uses a pipe, which is for chaining commands, not variable assignment. Option E assigns the literal string 'command' to the variable, not the output of the command. Therefore, A and C are the correct choices.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
var=`command`
Why this is correct
Backticks are an older syntax for command substitution, but still valid.
- ✗
var={command}
Why it's wrong here
Braces are not valid for command substitution in Bash.
- ✓
var=$(command)
Why this is correct
This is a modern and preferred syntax for command substitution.
- ✗
var|command
Why it's wrong here
This is a pipe, not assignment; it would pipe the value of var to command.
- ✗
var=command
Why it's wrong here
This assigns the string 'command' to var, not the output of the command.
Visual reference
Go deeper
Related to this question
About these practice questions
Courseiva writes every LPIC-1 question from scratch — 527 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.