Courseiva

EX200 Create simple shell scripts Practice Question

A script has a syntax error. Which command will help identify the line number of the error without executing the script?

⚠ Common exam trap

The Red Hat RHCSA exam often tests the distinction between syntax checking (`-n`) and execution tracing (`-x` or `-v`), so candidates mistakenly choose `set -x` thinking it will catch errors without execution, but it actually runs the script and only shows debug output.

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

✓

bash -n script.sh

The `bash -n` (noexec) option performs syntax checking on a script without executing any commands. If a syntax error exists, Bash reports the error along with the line number, making it the correct tool for identifying syntax errors in a script without running it.

Answer analysis

Option-by-option breakdown

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

  • ✗

    which bash

    Why it's wrong here

    The `which bash` command searches the directories listed in $PATH for an executable named `bash` and prints its absolute path, such as `/usr/bin/bash`. It performs no analysis of the script's contents and does not execute or parse the script in any way. Thus it can locate the shell interpreter but cannot reveal a syntax error in a script.

  • ✓

    bash -n script.sh

    Why this is correct

    The `bash -n script.sh` command invokes Bash's noexec mode, which causes the shell to read and parse the entire script but not execute any of its commands. The parser reports any syntax errors with the offending line number and returns a non-zero exit status, making this the standard method for syntax-checking a Bash script. Note that this check only validates grammar, not logical or runtime errors.

  • ✗

    set -x

    Why it's wrong here

    `set -x` turns on Bash's xtrace option, which prints each command to stderr after expansion but before execution. This tracing occurs only if the script is running; a script with a syntax error fails during the parsing phase, before any `set -x` output is produced. As a result, `set -x` is useful for following runtime execution flow, not for identifying syntax problems.

  • ✗

    bash -v script.sh

    Why it's wrong here

    The `bash -v script.sh` command runs the script in verbose mode, echoing each input line to stderr before it is executed. Like normal execution, the script must parse successfully before any lines are processed, and the `-v` option does not perform any separate syntax analysis. It simply displays what is being run, so while an error message might appear, `-v` does not help isolate or explain a syntax error.

About these practice questions

This EX200 question is part of Courseiva's 427-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.