You are writing a portable Bourne-compatible shell script that first counts running httpd processes:
proc_count=$(pgrep -c httpd)
The script must continue only when no such processes are running. Which test command, placed inside an if statement, will correctly make the then branch execute only when proc_count is exactly 0?
The expression [ "$proc_count" -eq 0 ] invokes the POSIX test (or [) utility and uses the -eq arithmetic operator, whose specification states "n1 -eq n2 - True if the integers n1 and n2 are algebraically equal." This returns exit status 0 only when the variable's value is the integer 0.
[[ "$proc_count" == 0 ]] performs a string comparison, so values like "00" would also match and it is not POSIX-portable. [ $proc_count -ne 0 ] is the logical opposite of what is needed, succeeding when at least one process is running. (( proc_count = 0 )) assigns 0 to the variable; the assignment's result is 0, yielding a false exit status, so the branch would never run.
Therefore, only the first test fulfills the requirement accurately and portably.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between `[ "$proc_count" -eq 0 ]` and `[[ "$proc_count" == 0 ]]`?
Open an interactive chat with Bash
What does the `-ne` operator in `[ $proc_count -ne 0 ]` do?
Open an interactive chat with Bash
Why is `(( proc_count = 0 ))` incorrect in this scenario?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .