Courseiva

EX200 Create simple shell scripts Practice Question

Which TWO of the following are correct statements about exit codes in shell scripts?

⚠ Common exam trap

A common pitfall is confusing the default exit code: many candidates assume the script always exits with 0 unless 'exit 1' is used, but actually the default exit code is the exit status of the last command run in the script.

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

✓

A non-zero exit code usually indicates a failure

In shell scripting, exit codes are integers from 0 to 255. An exit code of 0 conventionally indicates success, while any non-zero value (1–255) indicates a failure or error condition. Option B is correct because a non-zero exit code usually signals that the command or script did not complete successfully.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    An exit code of 1 means success

    Why it's wrong here

    In shell scripting, an exit status of 0 is the only value that denotes success. Exit code 1 is conventionally a generic catch-all for a failure or error condition, such as a command failing to find a file or a syntax error in a script. Therefore, interpreting an exit code of 1 as success inverts the standard convention and would mislead anyone troubleshooting the script's execution.

  • ✓

    A non-zero exit code usually indicates a failure

    Why this is correct

    The shell and many programs follow the convention that exit status 0 means successful completion, while any non-zero value signals an error, warning, or unusual termination. This convention is pervasive across UNIX-like systems and is relied upon by scripts, continuous integration pipelines, and command-line tools to make control-flow decisions. While specific programs may assign different meanings to specific non-zero codes, the general rule remains that non-zero means the command did not complete as intended.

  • ✗

    An exit code of -1 indicates a system error

    Why it's wrong here

    In the shell, exit codes are unsigned integer values in the range 0 through 255, inclusive. The value -1 is not representable as an exit status; if a script or command attempts to exit with -1, the shell typically mods the value by 256, so -1 becomes 255, which is commonly interpreted as a generic failure. There is no standard meaning of -1 as a "system error" in the context of process exit statuses.

  • ✗

    If no 'exit' is used, the script exits with code 0

    Why it's wrong here

    When a script reaches the end without an explicit exit statement, the shell uses the exit status of the last command executed as the script's exit status. If that final command fails, the script's exit status will be non-zero, not automatically 0. So omitting 'exit' does not guarantee a successful exit code; it makes the script's result dependent on whichever command happened to run last.

  • ✓

    Using 'exit 1' in a script sets the exit code to 1

    Why this is correct

    The exit built-in immediately terminates the current shell or script and returns its numeric argument as the process's exit status. Specifying 'exit 1' explicitly sets the status to 1, overriding whatever status the last command might have produced. This is a deliberate way for a script to signal a particular error condition to the calling process, which can then test $? to handle the failure appropriately.

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 →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.