EX200 Create simple shell scripts Practice Question
A sysadmin writes a shell script /usr/local/bin/check_service.sh that must accept exactly two positional arguments: a service name and a threshold. The script begins with:
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 <service> <threshold>" exit 1 fi
An operator runs the script as: ./check_service.sh httpd What is the exit status of the script, and what output is produced?
⚠ Common exam trap
The trap here is assuming that printing a usage message means the script succeeded, when the explicit exit 1 overrides that and returns failure to the caller.
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
✓
The script exits with status 1 and prints the usage line to standard output.
The script validates its argument count with $# and the numeric test -ne. With one positional argument supplied, the condition is true, so the usage message is written to standard output and exit 1 ends execution with a non-zero status. This is the conventional way to signal misuse from a shell script.
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 script exits with status 0 because the usage message is displayed successfully.
Why it's wrong here
The script explicitly calls exit 1 inside the argument-count check, so the exit status is 1, not 0. The successful display of the usage message does not affect the status returned by exit, and treating a usage error as success would mislead any calling automation.
- ✓
The script exits with status 1 and prints the usage line to standard output.
Why this is correct
Because only one argument is supplied, $# equals 1, the test [ $# -ne 2 ] is true, the usage message is echoed to standard output, and exit 1 terminates the script with status 1. This matches the intended argument-validation pattern.
- ✗
The script terminates with a syntax error because $# is not a valid variable.
Why it's wrong here
$# is a standard bash special parameter that expands to the number of positional parameters. It is valid inside test brackets, and the script parses without error. The failure here is purely the argument count, not the syntax of the check.
- ✗
The script continues past the check and prompts for the missing threshold value.
Why it's wrong here
Nothing in the script reads from standard input or prompts for values; the only branch taken when the count is wrong is the usage message followed by exit 1. The script does not attempt to recover by prompting, so it never reaches later logic.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX200 question from scratch — 427 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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Red Hat exam blueprint
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.