Unary Operator Expected Error — Common Cause and Fix with Quoting | Red Hat Certified System Administrator Explained
This EX200 practice question tests your understanding of create simple shell scripts. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
#!/bin/bash
if [ $var = "value" ]
then
echo "Match"
fi
Error: [: =: unary operator expected
Refer to the exhibit. The script produces the error shown. What is the most likely cause?
Clue words in this question
Noticing these words before you look at the options changes how you read each choice.
Clue: "most likely"
Why it matters: Probability qualifier — the question wants the most probable cause or outcome, not a guaranteed one. Eliminate low-probability options.
Exhibit
Refer to the exhibit.
#!/bin/bash
if [ $var = "value" ]
then
echo "Match"
fi
Error: [: =: unary operator expected
A
The = operator should be == for string comparison.
Why wrong: = is valid for string comparison in test; == is also valid but not required.
B
The string 'value' contains spaces.
Why wrong: It does not contain spaces; the error is about a missing argument.
C
The script is missing a valid shebang.
Why wrong: The shebang is present and correct.
D
The variable $var is empty or unset.
An empty variable leads to a missing operand error in [ ].
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The variable $var is empty or unset.
The error 'unary operator expected' occurs in bash when the `[ ]` test command encounters an empty or unset variable on the left side of a comparison operator. Since `$var` is empty, the expression `[ $var = 'value' ]` expands to `[ = 'value' ]`, which is syntactically invalid because the `=` operator expects a left operand. Option D correctly identifies this as the root cause.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✗
The = operator should be == for string comparison.
Why it's wrong here
= is valid for string comparison in test; == is also valid but not required.
✗
The string 'value' contains spaces.
Why it's wrong here
It does not contain spaces; the error is about a missing argument.
✗
The script is missing a valid shebang.
Why it's wrong here
The shebang is present and correct.
✓
The variable $var is empty or unset.
Why this is correct
An empty variable leads to a missing operand error in [ ].
Clue confirmation
The clue word "most likely" in the question point toward this answer.
Related concept
Read the scenario before looking for a memorised answer.
Common exam traps
Common exam trap: answer the scenario, not the keyword
The trap here is that candidates often blame the comparison operator (`=` vs `==`) or think the string contains spaces, when the real issue is an unquoted variable that becomes empty after expansion, causing a missing operand for the `=` operator. In a Red Hat environment, this is a common bash scripting pitfall.
Detailed technical explanation
How to think about this question
The `[` command (test) requires that both operands of a binary operator be present. When `$var` is unset, word splitting removes it entirely, leaving `[ = 'value' ]` — the `=` operator sees only one argument. Quoting the variable as `[ "$var" = 'value' ]` would expand to `[ '' = 'value' ]`, which is valid and returns false. This is a classic pitfall in shell scripting where unquoted variable expansions can cause syntax errors in test expressions.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A practitioner preparing for the EX200 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Create simple shell scripts — This question tests Create simple shell scripts — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: The variable $var is empty or unset. — The error 'unary operator expected' occurs in bash when the `[ ]` test command encounters an empty or unset variable on the left side of a comparison operator. Since `$var` is empty, the expression `[ $var = 'value' ]` expands to `[ = 'value' ]`, which is syntactically invalid because the `=` operator expects a left operand. Option D correctly identifies this as the root cause.
What should I do if I get this EX200 question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Are there clue words in this question I should notice?
Yes — watch for: "most likely". Probability qualifier — the question wants the most probable cause or outcome, not a guaranteed one. Eliminate low-probability options.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
This EX200 practice question is part of Courseiva's free Red Hat 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 EX200 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.